Title: [239935] trunk/Source/WebInspectorUI
- Revision
- 239935
- Author
- nvasil...@apple.com
- Date
- 2019-01-14 13:07:57 -0800 (Mon, 14 Jan 2019)
Log Message
Web Inspector: Styles: pressing Down key on empty value field shouldn't discard completion popover
https://bugs.webkit.org/show_bug.cgi?id=193098
<rdar://problem/47016036>
Reviewed by Devin Rousso.
Hide CompletionSuggestionsView when SpreadsheetTextField moves, e.g. by scrolling or resizing the sidebar.
Update CompletionSuggestionsView position after pressing Up or Down key, because SpreadsheetTextField may
move from wrapping text.
* UserInterface/Views/CompletionSuggestionsView.js:
(WI.CompletionSuggestionsView.prototype.hide):
(WI.CompletionSuggestionsView.prototype.show):
(WI.CompletionSuggestionsView.prototype.showUntilAnchorMoves): Removed.
(WI.CompletionSuggestionsView.prototype.hideWhenElementMoves): Added.
(WI.CompletionSuggestionsView.prototype._stopMoveTimer): Added.
(WI.CompletionSuggestionsView):
* UserInterface/Views/SpreadsheetTextField.js:
(WI.SpreadsheetTextField.prototype.set suggestionHint):
(WI.SpreadsheetTextField.prototype.completionSuggestionsSelectedCompletion):
(WI.SpreadsheetTextField.prototype._handleKeyDownForSuggestionView):
(WI.SpreadsheetTextField.prototype._updateCompletions):
(WI.SpreadsheetTextField.prototype._showSuggestionsView): Added.
(WI.SpreadsheetTextField.prototype._reAttachSuggestionHint):
Drive-by: abstract out repeating code into a private method.
Modified Paths
Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (239934 => 239935)
--- trunk/Source/WebInspectorUI/ChangeLog 2019-01-14 21:01:43 UTC (rev 239934)
+++ trunk/Source/WebInspectorUI/ChangeLog 2019-01-14 21:07:57 UTC (rev 239935)
@@ -1,3 +1,33 @@
+2019-01-14 Nikita Vasilyev <nvasil...@apple.com>
+
+ Web Inspector: Styles: pressing Down key on empty value field shouldn't discard completion popover
+ https://bugs.webkit.org/show_bug.cgi?id=193098
+ <rdar://problem/47016036>
+
+ Reviewed by Devin Rousso.
+
+ Hide CompletionSuggestionsView when SpreadsheetTextField moves, e.g. by scrolling or resizing the sidebar.
+ Update CompletionSuggestionsView position after pressing Up or Down key, because SpreadsheetTextField may
+ move from wrapping text.
+
+ * UserInterface/Views/CompletionSuggestionsView.js:
+ (WI.CompletionSuggestionsView.prototype.hide):
+ (WI.CompletionSuggestionsView.prototype.show):
+ (WI.CompletionSuggestionsView.prototype.showUntilAnchorMoves): Removed.
+ (WI.CompletionSuggestionsView.prototype.hideWhenElementMoves): Added.
+ (WI.CompletionSuggestionsView.prototype._stopMoveTimer): Added.
+ (WI.CompletionSuggestionsView):
+
+ * UserInterface/Views/SpreadsheetTextField.js:
+ (WI.SpreadsheetTextField.prototype.set suggestionHint):
+ (WI.SpreadsheetTextField.prototype.completionSuggestionsSelectedCompletion):
+ (WI.SpreadsheetTextField.prototype._handleKeyDownForSuggestionView):
+ (WI.SpreadsheetTextField.prototype._updateCompletions):
+ (WI.SpreadsheetTextField.prototype._showSuggestionsView): Added.
+
+ (WI.SpreadsheetTextField.prototype._reAttachSuggestionHint):
+ Drive-by: abstract out repeating code into a private method.
+
2019-01-14 Devin Rousso <drou...@apple.com>
Web Inspector: Settings: group titles should vertically align with the first editor
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CompletionSuggestionsView.js (239934 => 239935)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CompletionSuggestionsView.js 2019-01-14 21:01:43 UTC (rev 239934)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CompletionSuggestionsView.js 2019-01-14 21:07:57 UTC (rev 239935)
@@ -33,7 +33,7 @@
this._preventBlur = preventBlur || false;
this._selectedIndex = NaN;
- this._anchorBounds = null;
+ this._moveIntervalIdentifier = null;
this._element = document.createElement("div");
this._element.classList.add("completion-suggestions", WI.Popover.IgnoreAutoDismissClassName);
@@ -112,6 +112,8 @@
show(anchorBounds)
{
+ let scrollTop = this._containerElement.scrollTop;
+
// Measure the container so we can know the intrinsic size of the items.
this._containerElement.style.position = "absolute";
document.body.appendChild(this._containerElement);
@@ -156,40 +158,30 @@
this._element.style.height = height + "px";
document.body.appendChild(this._element);
+
+ if (scrollTop)
+ this._containerElement.scrollTop = scrollTop;
}
- showUntilAnchorMoves(getAnchorBounds)
+ hide()
{
- this._anchorBounds = getAnchorBounds();
- if (!this._anchorBounds) {
- this.hide();
- return;
- }
+ this._element.remove();
+ this._stopMoveTimer();
+ }
- this.show(this._anchorBounds);
+ hideWhenElementMoves(element)
+ {
+ this._stopMoveTimer();
+ let initialClientRect = element.getBoundingClientRect();
- let hideWhenMoved = () => {
- let anchorBounds = getAnchorBounds();
- if (!anchorBounds || !anchorBounds.equals(this._anchorBounds))
+ this._moveIntervalIdentifier = setInterval(() => {
+ let clientRect = element.getBoundingClientRect();
+ if (clientRect.x !== initialClientRect.x || clientRect.y !== initialClientRect.y)
this.hide();
- };
+ }, 200);
- if (this._hideWhenMovedIdentifier)
- clearInterval(this._hideWhenMovedIdentifier);
-
- this._hideWhenMovedIdentifier = setInterval(hideWhenMoved, 200);
}
- hide()
- {
- this._element.remove();
- this._anchorBounds = null;
- if (this._hideWhenMovedIdentifier) {
- clearInterval(this._hideWhenMovedIdentifier);
- this._hideWhenMovedIdentifier = 0;
- }
- }
-
update(completions, selectedIndex)
{
this._containerElement.removeChildren();
@@ -253,6 +245,15 @@
if (this._delegate && typeof this._delegate.completionSuggestionsClickedCompletion === "function")
this._delegate.completionSuggestionsClickedCompletion(this, itemElement.textContent);
}
+
+ _stopMoveTimer()
+ {
+ if (!this._moveIntervalIdentifier)
+ return;
+
+ clearInterval(this._moveIntervalIdentifier);
+ this._moveIntervalIdentifier = null;
+ }
};
WI.CompletionSuggestionsView.ItemElementStyleClassName = "item";
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js (239934 => 239935)
--- trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js 2019-01-14 21:01:43 UTC (rev 239934)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js 2019-01-14 21:07:57 UTC (rev 239935)
@@ -74,10 +74,9 @@
{
this._suggestionHintElement.textContent = value;
- if (value) {
- if (this._suggestionHintElement.parentElement !== this._element)
- this._element.append(this._suggestionHintElement);
- } else
+ if (value)
+ this._reAttachSuggestionHint();
+ else
this._suggestionHintElement.remove();
}
@@ -144,8 +143,7 @@
this.suggestionHint = selectedText.slice(completionPrefix.length);
- if (this._suggestionHintElement.parentElement !== this._element)
- this._element.append(this._suggestionHintElement);
+ this._reAttachSuggestionHint();
if (this._delegate && typeof this._delegate.spreadsheetTextFieldDidChange === "function")
this._delegate.spreadsheetTextFieldDidChange(this);
@@ -303,6 +301,9 @@
else
this._suggestionsView.selectPrevious();
+ // Update popover position in case text moved, e.g. started or stopped wrapping.
+ this._showSuggestionsView();
+
if (this._delegate && typeof this._delegate.spreadsheetTextFieldDidChange === "function")
this._delegate.spreadsheetTextFieldDidChange(this);
@@ -391,12 +392,8 @@
if (completions.length === 1) {
// No need to show the completion popover that matches the suggestion hint.
this._suggestionsView.hide();
- } else {
- let startOffset = prefix.length - completionPrefix.length;
- this._suggestionsView.showUntilAnchorMoves(() => {
- return this._getCaretRect(startOffset);
- });
- }
+ } else
+ this._showSuggestionsView();
this._suggestionsView.selectedIndex = NaN;
if (completionPrefix) {
@@ -406,6 +403,22 @@
this.suggestionHint = "";
}
+ _showSuggestionsView()
+ {
+ let prefix = this.valueWithoutSuggestion();
+ let completionPrefix = this._getCompletionPrefix(prefix);
+ let startOffset = prefix.length - completionPrefix.length;
+ let caretRect = this._getCaretRect(startOffset);
+
+ // Hide completion popover when the anchor element is removed from the DOM.
+ if (!caretRect)
+ this._suggestionsView.hide();
+ else {
+ this._suggestionsView.show(caretRect);
+ this._suggestionsView.hideWhenElementMoves(this._element);
+ }
+ }
+
_getCaretRect(startOffset)
{
let selection = window.getSelection();
@@ -451,4 +464,12 @@
this._element.textContent = this._element.textContent;
}
+
+ _reAttachSuggestionHint()
+ {
+ if (this._suggestionHintElement.parentElement === this._element)
+ return;
+
+ this._element.append(this._suggestionHintElement);
+ }
};
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes