Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/internal/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const ansi =
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
/* eslint-enable no-control-regex */

const kUTF16SurrogateThreshold = 0x10000; // 2 ** 16
const kEscape = '\x1b';

let getStringWidth;
Expand Down Expand Up @@ -63,7 +63,7 @@ if (internalBinding('config').hasIntl) {
for (var i = 0; i < str.length; i++) {
const code = str.codePointAt(i);

if (code >= 0x10000) { // surrogates
if (code >= kUTF16SurrogateThreshold) { // Surrogates.
i++;
}

Expand Down Expand Up @@ -434,6 +434,7 @@ module.exports = {
emitKeys,
getStringWidth,
isFullWidthCodePoint,
kUTF16SurrogateThreshold,
stripVTControlCharacters,
CSI
};
9 changes: 5 additions & 4 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const {
emitKeys,
getStringWidth,
isFullWidthCodePoint,
kUTF16SurrogateThreshold,
stripVTControlCharacters
} = require('internal/readline');

Expand Down Expand Up @@ -600,8 +601,8 @@ Interface.prototype._wordRight = function() {
function charLengthLeft(str, i) {
if (i <= 0)
return 0;
if (i > 1 && str.codePointAt(i - 2) >= 2 ** 16 ||
str.codePointAt(i - 1) >= 2 ** 16) {
if (i > 1 && str.codePointAt(i - 2) >= kUTF16SurrogateThreshold ||
str.codePointAt(i - 1) >= kUTF16SurrogateThreshold) {
return 2;
}
return 1;
Expand All @@ -610,7 +611,7 @@ function charLengthLeft(str, i) {
function charLengthAt(str, i) {
if (str.length <= i)
return 0;
return str.codePointAt(i) >= 2 ** 16 ? 2 : 1;
return str.codePointAt(i) >= kUTF16SurrogateThreshold ? 2 : 1;
}

Interface.prototype._deleteLeft = function() {
Expand Down Expand Up @@ -728,7 +729,7 @@ Interface.prototype._getDisplayPos = function(str) {
str = stripVTControlCharacters(str);
for (var i = 0, len = str.length; i < len; i++) {
code = str.codePointAt(i);
if (code >= 0x10000) { // surrogates
if (code >= kUTF16SurrogateThreshold) { // Surrogates.
i++;
}
if (code === 0x0a) { // new line \n
Expand Down