summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/devtools/front_end/text_editor
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-08-24 12:15:48 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-08-28 13:30:04 +0000
commitb014812705fc80bff0a5c120dfcef88f349816dc (patch)
tree25a2e2d9fa285f1add86aa333389a839f81a39ae /chromium/third_party/blink/renderer/devtools/front_end/text_editor
parent9f4560b1027ae06fdb497023cdcaf91b8511fa74 (diff)
downloadqtwebengine-chromium-b014812705fc80bff0a5c120dfcef88f349816dc.tar.gz
BASELINE: Update Chromium to 68.0.3440.125
Change-Id: I23f19369e01f688e496f5bf179abb521ad73874f Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/devtools/front_end/text_editor')
-rw-r--r--chromium/third_party/blink/renderer/devtools/front_end/text_editor/CodeMirrorTextEditor.js28
-rw-r--r--chromium/third_party/blink/renderer/devtools/front_end/text_editor/TextEditorAutocompleteController.js108
-rw-r--r--chromium/third_party/blink/renderer/devtools/front_end/text_editor/autocompleteTooltip.css19
-rw-r--r--chromium/third_party/blink/renderer/devtools/front_end/text_editor/cmdevtools.css8
-rw-r--r--chromium/third_party/blink/renderer/devtools/front_end/text_editor/module.json1
5 files changed, 148 insertions, 16 deletions
diff --git a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/CodeMirrorTextEditor.js b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/CodeMirrorTextEditor.js
index 2b74611bfe3..3d0a1cf1408 100644
--- a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/CodeMirrorTextEditor.js
+++ b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/CodeMirrorTextEditor.js
@@ -636,14 +636,18 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
}
/**
+ * @param {number} generation
* @return {boolean}
*/
- isClean() {
- return this._codeMirror.isClean();
+ isClean(generation) {
+ return this._codeMirror.isClean(generation);
}
+ /**
+ * @return {number}
+ */
markClean() {
- this._codeMirror.markClean();
+ return this._codeMirror.changeGeneration(true);
}
/**
@@ -1163,15 +1167,16 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
/**
* @override
* @param {!TextUtils.TextRange} textRange
+ * @param {boolean=} dontScroll
*/
- setSelection(textRange) {
+ setSelection(textRange, dontScroll) {
this._lastSelection = textRange;
if (!this._editorSizeInSync) {
this._selectionSetScheduled = true;
return;
}
const pos = TextEditor.CodeMirrorUtils.toPos(textRange);
- this._codeMirror.setSelection(pos.start, pos.end);
+ this._codeMirror.setSelection(pos.start, pos.end, {scroll: !dontScroll});
}
/**
@@ -1215,6 +1220,9 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
this._enableLongLinesMode();
else
this._disableLongLinesMode();
+
+ if (!this.isShowing())
+ this.refresh();
}
/**
@@ -1231,6 +1239,16 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
/**
* @override
+ * @return {string}
+ */
+ textWithCurrentSuggestion() {
+ if (!this._autocompleteController)
+ return this.text();
+ return this._autocompleteController.textWithCurrentSuggestion();
+ }
+
+ /**
+ * @override
* @return {!TextUtils.TextRange}
*/
fullRange() {
diff --git a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/TextEditorAutocompleteController.js b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/TextEditorAutocompleteController.js
index 56fbe6ce735..b74645c06ff 100644
--- a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/TextEditorAutocompleteController.js
+++ b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/TextEditorAutocompleteController.js
@@ -22,10 +22,25 @@ TextEditor.TextEditorAutocompleteController = class {
this._changes = this._changes.bind(this);
this._blur = this._blur.bind(this);
this._beforeChange = this._beforeChange.bind(this);
- this._mouseDown = this.clearAutocomplete.bind(this);
+ this._mouseDown = () => {
+ this.clearAutocomplete();
+ this._tooltipGlassPane.hide();
+ };
this._codeMirror.on('changes', this._changes);
this._lastHintText = '';
+ /** @type {?UI.SuggestBox} */
+ this._suggestBox = null;
+ /** @type {?string} */
+ this._currentSuggestion = null;
this._hintElement = createElementWithClass('span', 'auto-complete-text');
+
+ this._tooltipGlassPane = new UI.GlassPane();
+ this._tooltipGlassPane.setSizeBehavior(UI.GlassPane.SizeBehavior.MeasureContent);
+ this._tooltipGlassPane.setOutsideClickCallback(this._tooltipGlassPane.hide.bind(this._tooltipGlassPane));
+ this._tooltipElement = createElementWithClass('div', 'autocomplete-tooltip');
+ const shadowRoot =
+ UI.createShadowRootWithCoreStyles(this._tooltipGlassPane.contentElement, 'text_editor/autocompleteTooltip.css');
+ shadowRoot.appendChild(this._tooltipElement);
}
_initializeIfNeeded() {
@@ -216,14 +231,14 @@ TextEditor.TextEditorAutocompleteController = class {
autocomplete(force) {
this._initializeIfNeeded();
if (this._codeMirror.somethingSelected()) {
- this.clearAutocomplete();
+ this._hideSuggestBox();
return;
}
const cursor = this._codeMirror.getCursor('head');
const substituteRange = this._substituteRange(cursor.line, cursor.ch);
if (!substituteRange || !this._validateSelectionsContexts(substituteRange)) {
- this.clearAutocomplete();
+ this._hideSuggestBox();
return;
}
@@ -242,13 +257,14 @@ TextEditor.TextEditorAutocompleteController = class {
function wordsAcquired(wordsWithQuery) {
if (!wordsWithQuery.length || (wordsWithQuery.length === 1 && query === wordsWithQuery[0].text) ||
(!this._suggestBox && hadSuggestBox)) {
- this.clearAutocomplete();
+ this._hideSuggestBox();
this._onSuggestionsShownForTest([]);
return;
}
if (!this._suggestBox) {
- this._suggestBox = new UI.SuggestBox(this, 20, this._config.captureEnter);
- this._suggestBox.setDefaultSelectionIsDimmed(!!this._config.captureEnter);
+ this._suggestBox = new UI.SuggestBox(this, 20);
+ if (this._config.anchorBehavior)
+ this._suggestBox.setAnchorBehavior(this._config.anchorBehavior);
}
const oldQueryRange = this._queryRange;
@@ -257,6 +273,8 @@ TextEditor.TextEditorAutocompleteController = class {
queryRange.startColumn !== oldQueryRange.startColumn)
this._updateAnchorBox();
this._suggestBox.updateSuggestions(this._anchorBox, wordsWithQuery, true, !this._isCursorAtEndOfLine(), query);
+ if (this._suggestBox.visible)
+ this._tooltipGlassPane.hide();
this._onSuggestionsShownForTest(wordsWithQuery);
}
}
@@ -309,21 +327,32 @@ TextEditor.TextEditorAutocompleteController = class {
}
clearAutocomplete() {
+ this._tooltipGlassPane.hide();
+ this._hideSuggestBox();
+ }
+
+ _hideSuggestBox() {
if (!this._suggestBox)
return;
this._suggestBox.hide();
this._suggestBox = null;
this._queryRange = null;
this._anchorBox = null;
+ this._currentSuggestion = null;
+ this._textEditor.dispatchEventToListeners(UI.TextEditor.Events.SuggestionChanged);
this._clearHint();
this._onSuggestionsHiddenForTest();
}
/**
- * @param {!Event} event
+ * @param {!KeyboardEvent} event
* @return {boolean}
*/
keyDown(event) {
+ if (this._tooltipGlassPane.isShowing() && event.keyCode === UI.KeyboardShortcut.Keys.Esc.code) {
+ this._tooltipGlassPane.hide();
+ return true;
+ }
if (!this._suggestBox)
return false;
switch (event.keyCode) {
@@ -366,8 +395,11 @@ TextEditor.TextEditorAutocompleteController = class {
* @param {boolean=} isIntermediateSuggestion
*/
applySuggestion(suggestion, isIntermediateSuggestion) {
+ const oldSuggestion = this._currentSuggestion;
this._currentSuggestion = suggestion;
this._setHint(suggestion);
+ if (oldSuggestion !== suggestion)
+ this._textEditor.dispatchEventToListeners(UI.TextEditor.Events.SuggestionChanged);
}
/**
@@ -376,14 +408,41 @@ TextEditor.TextEditorAutocompleteController = class {
acceptSuggestion() {
const selections = this._codeMirror.listSelections().slice();
const queryLength = this._queryRange.endColumn - this._queryRange.startColumn;
- for (let i = selections.length - 1; i >= 0; --i) {
- const start = selections[i].head;
- const end = new CodeMirror.Pos(start.line, start.ch - queryLength);
- this._codeMirror.replaceRange(this._currentSuggestion, start, end, '+autocomplete');
+ const suggestion = this._currentSuggestion;
+ this._codeMirror.operation(() => {
+ for (let i = selections.length - 1; i >= 0; --i) {
+ const start = selections[i].head;
+ const end = new CodeMirror.Pos(start.line, start.ch - queryLength);
+ this._codeMirror.replaceRange(suggestion, start, end, '+autocomplete');
+ }
+ });
+ }
+
+ /**
+ * @return {string}
+ */
+ textWithCurrentSuggestion() {
+ if (!this._queryRange || this._currentSuggestion === null)
+ return this._codeMirror.getValue();
+
+ const selections = this._codeMirror.listSelections().slice();
+ let last = {line: 0, column: 0};
+ let text = '';
+ const queryLength = this._queryRange.endColumn - this._queryRange.startColumn;
+ for (const selection of selections) {
+ const range =
+ new TextUtils.TextRange(last.line, last.column, selection.head.line, selection.head.ch - queryLength);
+ text += this._textEditor.text(range);
+ text += this._currentSuggestion;
+ last = {line: selection.head.line, column: selection.head.ch};
}
+ const range = new TextUtils.TextRange(last.line, last.column, Infinity, Infinity);
+ text += this._textEditor.text(range);
+ return text;
}
_onScroll() {
+ this._tooltipGlassPane.hide();
if (!this._suggestBox)
return;
const cursor = this._codeMirror.getCursor();
@@ -398,7 +457,34 @@ TextEditor.TextEditorAutocompleteController = class {
}
}
+ async _updateTooltip() {
+ const cursor = this._codeMirror.getCursor();
+ const tooltip = this._config.tooltipCallback ? await this._config.tooltipCallback(cursor.line, cursor.ch) : null;
+ const newCursor = this._codeMirror.getCursor();
+
+ if (newCursor.line !== cursor.line && newCursor.ch !== cursor.ch)
+ return;
+ if (this._suggestBox && this._suggestBox.visible)
+ return;
+
+ if (!tooltip) {
+ this._tooltipGlassPane.hide();
+ return;
+ }
+ const metrics = this._textEditor.cursorPositionToCoordinates(cursor.line, cursor.ch);
+ if (!metrics) {
+ this._tooltipGlassPane.hide();
+ return;
+ }
+
+ this._tooltipGlassPane.setContentAnchorBox(new AnchorBox(metrics.x, metrics.y, 0, metrics.height));
+ this._tooltipElement.removeChildren();
+ this._tooltipElement.appendChild(tooltip);
+ this._tooltipGlassPane.show(/** @type {!Document} */ (this._textEditor.element.ownerDocument));
+ }
+
_onCursorActivity() {
+ this._updateTooltip();
if (!this._suggestBox)
return;
const cursor = this._codeMirror.getCursor();
diff --git a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/autocompleteTooltip.css b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/autocompleteTooltip.css
new file mode 100644
index 00000000000..763a77091c1
--- /dev/null
+++ b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/autocompleteTooltip.css
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2018 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+.autocomplete-tooltip {
+ pointer-events: none;
+ margin-left: -3px;
+}
+
+.autocomplete-tooltip > div > * {
+ padding: 0px 4px;
+ white-space: nowrap;
+ vertical-align: middle;
+ line-height: 20px;
+ box-shadow: var(--drop-shadow);
+ background-color: #FFFFFF;
+ width: fit-content;
+} \ No newline at end of file
diff --git a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/cmdevtools.css b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/cmdevtools.css
index 5ff40d86965..f30c3340dbe 100644
--- a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/cmdevtools.css
+++ b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/cmdevtools.css
@@ -114,6 +114,10 @@
white-space: nowrap;
}
+.pretty-printed .CodeMirror-linenumber {
+ color: var( --accent-color-b);
+}
+
.cm-highlight {
-webkit-animation: fadeout 2s 0s;
}
@@ -546,3 +550,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {
.CodeMirror-composing {
border-bottom: 2px solid;
}
+
+.pretty-printed .CodeMirror-linenumber {
+ color: var(--accent-color-b);
+}
diff --git a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/module.json b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/module.json
index 429098b6fdc..e1a6b600fc8 100644
--- a/chromium/third_party/blink/renderer/devtools/front_end/text_editor/module.json
+++ b/chromium/third_party/blink/renderer/devtools/front_end/text_editor/module.json
@@ -26,6 +26,7 @@
"CodeMirrorTextEditor.js"
],
"resources": [
+ "autocompleteTooltip.css",
"cmdevtools.css"
],
"skip_compilation": [