Title: [288498] branches/safari-613-branch
Revision
288498
Author
repst...@apple.com
Date
2022-01-24 17:54:51 -0800 (Mon, 24 Jan 2022)

Log Message

Cherry-pick r287934. rdar://problem/86578732

    Web Inspector: Unhandled exception when moving cursor mid-token after receiving CSS property name completions
    https://bugs.webkit.org/show_bug.cgi?id=234393
    <rdar://problem/86578732>

    Reviewed by Patrick Angle.

    Source/WebInspectorUI:

    A faulty check for mid-token completions in `WI.CSSKeywordCompletions.forPartialPropertyName()`, which are still
    unsupported, prevented an early return and completions were provided unexpectedly. This had knock-on effects in
    `WI.SpreadsheetTextField` which is not set up to handle cases where the caret is placed within the completion query.
    Calculating the adjusted caret position could return a negative index and throw an unhandled exception.

    Web Inspector does not currently explicitly support mid-token completions. See https://webkit.org/b/227157

    The implementation of fuzzy matching for CSS completions in https://webkit.org/b/234092
    means that, unhindered, the completion provider for CSS property names _can_ return mid-token completions.
    Typing a query like `margin`, then moving the caret to the beginning and correcting to `s|margin` will return
    completions like `[s]croll-[margin]`. Accepting the completion results in a malformed `SpreadsheetTextField.value`
    by concatenation within the prefix itself. As the user types mid-token, the prefix becomes ambiguous.

    Fixing the condition in `WI.CSSKeywordCompletions.forPartialPropertyName()` now inhibits unintentional
    mid-token completions when fuzzy matching is enabled.

    * UserInterface/Models/CSSKeywordCompletions.js:
    (WI.CSSKeywordCompletions.forPartialPropertyName):
    * UserInterface/Views/SpreadsheetTextField.js:
    (WI.SpreadsheetTextField.prototype._showSuggestionsView):

    LayoutTests:

    * inspector/unit-tests/css-keyword-completions-expected.txt:
    * inspector/unit-tests/css-keyword-completions.html:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287934 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (288497 => 288498)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-01-25 01:54:47 UTC (rev 288497)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-01-25 01:54:51 UTC (rev 288498)
@@ -1,5 +1,57 @@
 2022-01-24  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r287934. rdar://problem/86578732
+
+    Web Inspector: Unhandled exception when moving cursor mid-token after receiving CSS property name completions
+    https://bugs.webkit.org/show_bug.cgi?id=234393
+    <rdar://problem/86578732>
+    
+    Reviewed by Patrick Angle.
+    
+    Source/WebInspectorUI:
+    
+    A faulty check for mid-token completions in `WI.CSSKeywordCompletions.forPartialPropertyName()`, which are still
+    unsupported, prevented an early return and completions were provided unexpectedly. This had knock-on effects in
+    `WI.SpreadsheetTextField` which is not set up to handle cases where the caret is placed within the completion query.
+    Calculating the adjusted caret position could return a negative index and throw an unhandled exception.
+    
+    Web Inspector does not currently explicitly support mid-token completions. See https://webkit.org/b/227157
+    
+    The implementation of fuzzy matching for CSS completions in https://webkit.org/b/234092
+    means that, unhindered, the completion provider for CSS property names _can_ return mid-token completions.
+    Typing a query like `margin`, then moving the caret to the beginning and correcting to `s|margin` will return
+    completions like `[s]croll-[margin]`. Accepting the completion results in a malformed `SpreadsheetTextField.value`
+    by concatenation within the prefix itself. As the user types mid-token, the prefix becomes ambiguous.
+    
+    Fixing the condition in `WI.CSSKeywordCompletions.forPartialPropertyName()` now inhibits unintentional
+    mid-token completions when fuzzy matching is enabled.
+    
+    * UserInterface/Models/CSSKeywordCompletions.js:
+    (WI.CSSKeywordCompletions.forPartialPropertyName):
+    * UserInterface/Views/SpreadsheetTextField.js:
+    (WI.SpreadsheetTextField.prototype._showSuggestionsView):
+    
+    LayoutTests:
+    
+    * inspector/unit-tests/css-keyword-completions-expected.txt:
+    * inspector/unit-tests/css-keyword-completions.html:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287934 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-12  Razvan Caliman  <rcali...@apple.com>
+
+            Web Inspector: Unhandled exception when moving cursor mid-token after receiving CSS property name completions
+            https://bugs.webkit.org/show_bug.cgi?id=234393
+            <rdar://problem/86578732>
+
+            Reviewed by Patrick Angle.
+
+            * inspector/unit-tests/css-keyword-completions-expected.txt:
+            * inspector/unit-tests/css-keyword-completions.html:
+
+2022-01-24  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r287922. rdar://problem/87455957
 
     [LFC][IFC] Incorrect negative margin handling (both left/right) with RTL inline base direction

Modified: branches/safari-613-branch/LayoutTests/inspector/unit-tests/css-keyword-completions-expected.txt (288497 => 288498)


--- branches/safari-613-branch/LayoutTests/inspector/unit-tests/css-keyword-completions-expected.txt	2022-01-25 01:54:47 UTC (rev 288497)
+++ branches/safari-613-branch/LayoutTests/inspector/unit-tests/css-keyword-completions-expected.txt	2022-01-25 01:54:51 UTC (rev 288498)
@@ -15,6 +15,10 @@
 -- Running test case: WI.CSSKeywordCompletions.forPartialPropertyName.multipleCharacterMatches
 PASS: All expected completions were present.
 
+-- Running test case: WI.CSSKeywordCompletions.forPartialPropertyName.midTokenNoCompletions
+PASS: Expected exactly 0 completion results.
+PASS: All expected completions were present.
+
 -- Running test case: WI.CSSKeywordCompletions.forPartialPropertyValue.EmptyTop
 PASS: Expected result prefix to be ""
 PASS: All expected completions were present.

Modified: branches/safari-613-branch/LayoutTests/inspector/unit-tests/css-keyword-completions.html (288497 => 288498)


--- branches/safari-613-branch/LayoutTests/inspector/unit-tests/css-keyword-completions.html	2022-01-25 01:54:47 UTC (rev 288497)
+++ branches/safari-613-branch/LayoutTests/inspector/unit-tests/css-keyword-completions.html	2022-01-25 01:54:51 UTC (rev 288498)
@@ -7,7 +7,7 @@
 {
     let suite = InspectorTest.createSyncSuite("WI.CSSKeywordCompletions");
 
-    function addTestForPartialPropertyName({name, description, text, allowEmptyPrefix, expectedCompletions, expectedCompletionCount}) {
+    function addTestForPartialPropertyName({name, description, text, caretPosition, allowEmptyPrefix, expectedCompletions, expectedCompletionCount}) {
         suite.addTestCase({
             name,
             description,
@@ -17,7 +17,7 @@
                 expectedCompletionCount ??= -1;
 
                 // FIXME: <webkit.org/b/227157> Styles: Support completions mid-token.
-                let caretPosition = text.length;
+                caretPosition ??= text.length;
                 let completionResults = WI.CSSKeywordCompletions.forPartialPropertyName(text, {caretPosition, allowEmptyPrefix});
 
                 if (expectedCompletionCount >= 0)
@@ -66,6 +66,15 @@
         expectedCompletions: ["range"],
     });
 
+    // FIXME: This test will fail after addressing <webkit.org/b/227157> Styles: Support completions mid-token.
+    addTestForPartialPropertyName({
+        name: "WI.CSSKeywordCompletions.forPartialPropertyName.midTokenNoCompletions",
+        description: "Test that completions are not provided when the caret is positioned within the token.",
+        text: "margin",
+        caretPosition: 1,
+        expectedCompletionCount: 0,
+    });
+
     function addTestForPartialPropertyValue({name, description, propertyName, text, caretPosition, expectedPrefix, expectedCompletions, expectedCompletionCount, additionalFunctionValueCompletionsProvider}) {
         suite.addTestCase({
             name,

Modified: branches/safari-613-branch/Source/WebInspectorUI/ChangeLog (288497 => 288498)


--- branches/safari-613-branch/Source/WebInspectorUI/ChangeLog	2022-01-25 01:54:47 UTC (rev 288497)
+++ branches/safari-613-branch/Source/WebInspectorUI/ChangeLog	2022-01-25 01:54:51 UTC (rev 288498)
@@ -1,5 +1,75 @@
 2022-01-24  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r287934. rdar://problem/86578732
+
+    Web Inspector: Unhandled exception when moving cursor mid-token after receiving CSS property name completions
+    https://bugs.webkit.org/show_bug.cgi?id=234393
+    <rdar://problem/86578732>
+    
+    Reviewed by Patrick Angle.
+    
+    Source/WebInspectorUI:
+    
+    A faulty check for mid-token completions in `WI.CSSKeywordCompletions.forPartialPropertyName()`, which are still
+    unsupported, prevented an early return and completions were provided unexpectedly. This had knock-on effects in
+    `WI.SpreadsheetTextField` which is not set up to handle cases where the caret is placed within the completion query.
+    Calculating the adjusted caret position could return a negative index and throw an unhandled exception.
+    
+    Web Inspector does not currently explicitly support mid-token completions. See https://webkit.org/b/227157
+    
+    The implementation of fuzzy matching for CSS completions in https://webkit.org/b/234092
+    means that, unhindered, the completion provider for CSS property names _can_ return mid-token completions.
+    Typing a query like `margin`, then moving the caret to the beginning and correcting to `s|margin` will return
+    completions like `[s]croll-[margin]`. Accepting the completion results in a malformed `SpreadsheetTextField.value`
+    by concatenation within the prefix itself. As the user types mid-token, the prefix becomes ambiguous.
+    
+    Fixing the condition in `WI.CSSKeywordCompletions.forPartialPropertyName()` now inhibits unintentional
+    mid-token completions when fuzzy matching is enabled.
+    
+    * UserInterface/Models/CSSKeywordCompletions.js:
+    (WI.CSSKeywordCompletions.forPartialPropertyName):
+    * UserInterface/Views/SpreadsheetTextField.js:
+    (WI.SpreadsheetTextField.prototype._showSuggestionsView):
+    
+    LayoutTests:
+    
+    * inspector/unit-tests/css-keyword-completions-expected.txt:
+    * inspector/unit-tests/css-keyword-completions.html:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287934 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-12  Razvan Caliman  <rcali...@apple.com>
+
+            Web Inspector: Unhandled exception when moving cursor mid-token after receiving CSS property name completions
+            https://bugs.webkit.org/show_bug.cgi?id=234393
+            <rdar://problem/86578732>
+
+            Reviewed by Patrick Angle.
+
+            A faulty check for mid-token completions in `WI.CSSKeywordCompletions.forPartialPropertyName()`, which are still
+            unsupported, prevented an early return and completions were provided unexpectedly. This had knock-on effects in
+            `WI.SpreadsheetTextField` which is not set up to handle cases where the caret is placed within the completion query.
+            Calculating the adjusted caret position could return a negative index and throw an unhandled exception.
+
+            Web Inspector does not currently explicitly support mid-token completions. See https://webkit.org/b/227157
+
+            The implementation of fuzzy matching for CSS completions in https://webkit.org/b/234092
+            means that, unhindered, the completion provider for CSS property names _can_ return mid-token completions.
+            Typing a query like `margin`, then moving the caret to the beginning and correcting to `s|margin` will return
+            completions like `[s]croll-[margin]`. Accepting the completion results in a malformed `SpreadsheetTextField.value`
+            by concatenation within the prefix itself. As the user types mid-token, the prefix becomes ambiguous.
+
+            Fixing the condition in `WI.CSSKeywordCompletions.forPartialPropertyName()` now inhibits unintentional
+            mid-token completions when fuzzy matching is enabled.
+
+            * UserInterface/Models/CSSKeywordCompletions.js:
+            (WI.CSSKeywordCompletions.forPartialPropertyName):
+            * UserInterface/Views/SpreadsheetTextField.js:
+            (WI.SpreadsheetTextField.prototype._showSuggestionsView):
+
+2022-01-24  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r287870. rdar://problem/86543279
 
     Web Inspector: Increase padding around icons in Alignment editor

Modified: branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js (288497 => 288498)


--- branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js	2022-01-25 01:54:47 UTC (rev 288497)
+++ branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js	2022-01-25 01:54:51 UTC (rev 288498)
@@ -33,12 +33,11 @@
 
 WI.CSSKeywordCompletions.forPartialPropertyName = function(text, {caretPosition, allowEmptyPrefix, useFuzzyMatching} = {})
 {
-    caretPosition ??= text.length;
     allowEmptyPrefix ??= false;
 
     // FIXME: <webkit.org/b/227157> Styles: Support completions mid-token.
-    if (caretPosition !== caretPosition)
-        return {prefix: text, completions: []};
+    if (caretPosition !== text.length)
+        return {prefix: "", completions: []};
 
     if (!text.length && allowEmptyPrefix)
         return {prefix: text, completions: WI.cssManager.propertyNameCompletions.values};

Modified: branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js (288497 => 288498)


--- branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js	2022-01-25 01:54:47 UTC (rev 288497)
+++ branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js	2022-01-25 01:54:51 UTC (rev 288498)
@@ -478,6 +478,8 @@
         // border: 1px solid ro|
         //                   rosybrown
         //                   royalblue
+        //
+        // FIXME: Account for the caret being within the token when fixing <webkit.org/b/227157> Styles: Support completions mid-token.
         let adjustedCaretPosition = this._getCaretPosition() - this._completionPrefix.length;
         let caretRect = this._getCaretRect(adjustedCaretPosition);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to