Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js (208247 => 208248)
--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js 2016-11-01 21:49:40 UTC (rev 208247)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js 2016-11-01 21:56:11 UTC (rev 208248)
@@ -58,6 +58,7 @@
"Cmd-Y": this._handleHideKey.bind(this)
};
+ this._handleBeforeChangeListener = this._handleBeforeChange.bind(this);
this._handleChangeListener = this._handleChange.bind(this);
this._handleCursorActivityListener = this._handleCursorActivity.bind(this);
this._handleHideActionListener = this._handleHideAction.bind(this);
@@ -64,6 +65,7 @@
this._codeMirror.addKeyMap(this._keyMap);
+ this._codeMirror.on("beforeChange", this._handleBeforeChangeListener);
this._codeMirror.on("change", this._handleChangeListener);
this._codeMirror.on("cursorActivity", this._handleCursorActivityListener);
this._codeMirror.on("blur", this._handleHideActionListener);
@@ -70,6 +72,12 @@
this._codeMirror.on("scroll", this._handleHideActionListener);
this._updatePromise = null;
+
+ this._currentCompletion = null;
+ this._ignoreChange = false;
+ this._ignoreNextCursorActivity = false;
+ this._ignoreNextUndo = false;
+ this._inCompletionActivity = false;
}
// Public
@@ -86,8 +94,10 @@
updateCompletions(completions, implicitSuffix)
{
- if (isNaN(this._startOffset) || isNaN(this._endOffset) || isNaN(this._lineNumber))
+ if (isNaN(this._startOffset) || isNaN(this._endOffset) || isNaN(this._lineNumber)) {
+ this._inCompletionActivity = false;
return;
+ }
if (!completions || !completions.length) {
this.hideCompletions();
@@ -133,7 +143,7 @@
isCompletionChange(change)
{
- return this._ignoreChange || change.origin === WebInspector.CodeMirrorCompletionController.CompletionOrigin || change.origin === WebInspector.CodeMirrorCompletionController.DeleteCompletionOrigin;
+ return this._ignoreChange || this._ignoreNextUndo || change.origin === WebInspector.CodeMirrorCompletionController.CompletionOrigin || change.origin === WebInspector.CodeMirrorCompletionController.DeleteCompletionOrigin;
}
isShowingCompletions()
@@ -160,8 +170,9 @@
this._implicitSuffix = "";
this._forced = false;
- delete this._currentCompletion;
- delete this._ignoreNextCursorActivity;
+ this._currentCompletion = null;
+ this._ignoreNextCursorActivity = false;
+ this._inCompletionActivity = false;
this._resolveUpdatePromise(WebInspector.CodeMirrorCompletionController.UpdatePromise.NoCompletionsFound);
}
@@ -170,6 +181,7 @@
{
this._codeMirror.removeKeyMap(this._keyMap);
+ this._codeMirror.off("beforeChange", this._handleBeforeChangeListener);
this._codeMirror.off("change", this._handleChangeListener);
this._codeMirror.off("cursorActivity", this._handleCursorActivityListener);
this._codeMirror.off("blur", this._handleHideActionListener);
@@ -191,6 +203,8 @@
completionSuggestionsSelectedCompletion(suggestionsView, completionText)
{
+ this._ignoreNextUndo = true;
+
this._applyCompletionHint(completionText);
}
@@ -245,15 +259,6 @@
this._notifyCompletionsHiddenIfNeededTimeout = setTimeout(notify.bind(this), WebInspector.CodeMirrorCompletionController.CompletionsHiddenDelay);
}
- _createCompletionHintMarker(position, text)
- {
- var container = document.createElement("span");
- container.classList.add(WebInspector.CodeMirrorCompletionController.CompletionHintStyleClassName);
- container.textContent = text;
-
- this._completionHintMarker = this._codeMirror.setUniqueBookmark(position, {widget: container, insertLeft: true});
- }
-
_applyCompletionHint(completionText)
{
console.assert(completionText);
@@ -262,17 +267,26 @@
function update()
{
+ if (!this._inCompletionActivity) {
+ this._inCompletionActivity = true;
+ this._codeMirror.changeGeneration(true);
+ }
+
this._currentCompletion = completionText;
- this._removeCompletionHint(true, true);
+ this._removeCompletionHint(true);
- var replacementText = this._currentReplacementText;
+ let replacementText = this._currentReplacementText;
- var from = {line: this._lineNumber, ch: this._startOffset};
- var cursor = {line: this._lineNumber, ch: this._endOffset};
- var currentText = this._codeMirror.getRange(from, cursor);
+ let from = {line: this._lineNumber, ch: this._startOffset};
+ let cursor = {line: this._lineNumber, ch: this._endOffset};
+ let to = {line: this._lineNumber, ch: this._startOffset + replacementText.length};
- this._createCompletionHintMarker(cursor, replacementText.replace(currentText, ""));
+ this._codeMirror.replaceRange(replacementText, from, cursor, WebInspector.CodeMirrorCompletionController.CompletionOrigin);
+
+ this._codeMirror.setCursor(cursor);
+ if (cursor.ch !== to.ch)
+ this._completionHintMarker = this._codeMirror.markText(cursor, to, {className: WebInspector.CodeMirrorCompletionController.CompletionHintStyleClassName});
}
this._ignoreChange = true;
@@ -280,7 +294,7 @@
this._codeMirror.operation(update.bind(this));
- delete this._ignoreChange;
+ this._ignoreChange = false;
}
_commitCompletionHint()
@@ -287,7 +301,7 @@
{
function update()
{
- this._removeCompletionHint(true, true);
+ this._removeCompletionHint(true);
var replacementText = this._currentReplacementText;
@@ -302,8 +316,6 @@
this._codeMirror.replaceRange(replacementText, from, cursor, WebInspector.CodeMirrorCompletionController.CompletionOrigin);
- // Don't call _removeLastChangeFromHistory here to allow the committed completion to be undone.
-
this._codeMirror.setCursor(to);
this.hideCompletions();
@@ -314,71 +326,35 @@
this._codeMirror.operation(update.bind(this));
- delete this._ignoreChange;
+ this._ignoreChange = false;
}
- _removeLastChangeFromHistory()
+ _removeCompletionHint(nonatomic)
{
- var history = this._codeMirror.getHistory();
-
- // We don't expect a undone history. But if there is one clear it. If could lead to undefined behavior.
- console.assert(!history.undone.length);
- history.undone = [];
-
- // Pop the last item from the done history.
- console.assert(history.done.length);
- history.done.pop();
-
- this._codeMirror.setHistory(history);
- }
-
- _removeCompletionHint(nonatomic, dontRestorePrefix)
- {
if (!this._completionHintMarker)
return;
this._notifyCompletionsHiddenSoon();
- function clearMarker(marker)
+ function update()
{
- if (!marker)
- return;
+ this._codeMirror.undo();
- var range = marker.find();
+ let range = this._completionHintMarker.find();
if (range)
- marker.clear();
+ this._completionHintMarker.clear();
- return null;
+ this._completionHintMarker = null;
}
- function update()
- {
- this._completionHintMarker = clearMarker(this._completionHintMarker);
+ this._ignoreChange = true;
- if (dontRestorePrefix)
- return;
-
- console.assert(!isNaN(this._startOffset));
- console.assert(!isNaN(this._endOffset));
- console.assert(!isNaN(this._lineNumber));
-
- var from = {line: this._lineNumber, ch: this._startOffset};
- var to = {line: this._lineNumber, ch: this._endOffset};
-
- this._codeMirror.replaceRange(this._prefix, from, to, WebInspector.CodeMirrorCompletionController.DeleteCompletionOrigin);
- this._removeLastChangeFromHistory();
- }
-
- if (nonatomic) {
+ if (nonatomic)
update.call(this);
- return;
- }
+ else
+ this._codeMirror.operation(update.bind(this));
- this._ignoreChange = true;
-
- this._codeMirror.operation(update.bind(this));
-
- delete this._ignoreChange;
+ this._ignoreChange = false;
}
_scanStringForExpression(modeName, string, startOffset, direction, allowMiddleAndEmpty, includeStopCharacter, ignoreInitialUnmatchedOpenBracket, stopCharactersRegex)
@@ -462,7 +438,7 @@
return;
}
- this._removeCompletionHint(true, true);
+ this._removeCompletionHint(true);
var cursor = this._codeMirror.getCursor();
var token = this._codeMirror.getTokenAt(cursor);
@@ -807,6 +783,17 @@
this._applyCompletionHint(this._currentCompletion);
}
+ _handleBeforeChange(codeMirror, change)
+ {
+ if (this.isCompletionChange(change))
+ return;
+
+ this._ignoreNextCursorActivity = true;
+
+ if (this.isShowingCompletions())
+ this.hideCompletions();
+ }
+
_handleChange(codeMirror, change)
{
if (this.isCompletionChange(change))
@@ -814,6 +801,11 @@
this._ignoreNextCursorActivity = true;
+ if (this._ignoreNextUndo && change.origin === "undo") {
+ this._ignoreNextUndo = false;
+ return;
+ }
+
if (!change.origin || change.origin.charAt(0) !== "+") {
this.hideCompletions();
return;
@@ -832,7 +824,7 @@
return;
if (this._ignoreNextCursorActivity) {
- delete this._ignoreNextCursorActivity;
+ this._ignoreNextCursorActivity = false;
return;
}