@@ -569,8 +569,11 @@ function commonPrefix(strings) { |
|
|
569 |
569 |
|
570 |
570 |
Interface.prototype._wordLeft = function() { |
571 |
571 |
if (this.cursor > 0) { |
|
572 |
+// Reverse the string and match a word near beginning |
|
573 |
+// to avoid quadratic time complexity |
572 |
574 |
var leading = this.line.slice(0, this.cursor); |
573 |
|
-var match = leading.match(/(?:[^\w\s]+|\w+ |
|
575 |
+var reversed = leading.split('').reverse().join(''); |
|
576 |
+var match = reversed.match(/^\s*(?:[^\w\s]+|\w+)?/); |
574 |
577 |
this._moveCursor(-match[0].length); |
575 |
578 |
} |
576 |
579 |
}; |
@@ -626,8 +629,11 @@ Interface.prototype._deleteRight = function() { |
|
|
626 |
629 |
|
627 |
630 |
Interface.prototype._deleteWordLeft = function() { |
628 |
631 |
if (this.cursor > 0) { |
|
632 |
+// Reverse the string and match a word near beginning |
|
633 |
+// to avoid quadratic time complexity |
629 |
634 |
var leading = this.line.slice(0, this.cursor); |
630 |
|
-var match = leading.match(/(?:[^\w\s]+|\w+ |
|
635 |
+var reversed = leading.split('').reverse().join(''); |
|
636 |
+var match = reversed.match(/^\s*(?:[^\w\s]+|\w+)?/); |
631 |
637 |
leading = leading.slice(0, leading.length - match[0].length); |
632 |
638 |
this.line = leading + this.line.slice(this.cursor, this.line.length); |
633 |
639 |
this.cursor = leading.length; |