WebKit Bugzilla
Attachment 361144 Details for
Bug 182523
: Web Inspector: Styles: close unbalanced quotes and parenthesis when editing values
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
patch.txt (text/plain), 5.59 KB, created by
Nikita Vasilyev
on 2019-02-04 18:15:05 PST
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Nikita Vasilyev
Created:
2019-02-04 18:15:05 PST
Size:
5.59 KB
patch
obsolete
>diff --git a/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js b/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js >index 09d61048421..aa83da947f8 100644 >--- a/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js >+++ b/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js >@@ -171,6 +171,81 @@ WI.CSSCompletions = class CSSCompletions > target.CSSAgent.getSupportedSystemFontFamilyNames(fontFamilyNamesCallback); > } > >+ static fixUnbalancedCharacters(value) >+ { >+ const State = { >+ Data: 0, >+ SingleQuoteString: 2, >+ DoubleQuoteString: 3, >+ Comment: 4 >+ }; >+ >+ let state = State.Data; >+ let parenthesisUnclosedCount = 0; >+ >+ let length = value.length; >+ for (let i = 0; i < length; ++i) { >+ let char = value[i]; >+ switch (char) { >+ case "'": >+ if (state === State.Data) >+ state = State.SingleQuoteString; >+ else if (state === State.SingleQuoteString) >+ state = State.Data; >+ break; >+ >+ case "\"": >+ if (state === State.Data) >+ state = State.DoubleQuoteString; >+ else if (state === State.DoubleQuoteString) >+ state = State.Data; >+ break; >+ >+ case "(": >+ if (state === State.Data) >+ ++parenthesisUnclosedCount; >+ break; >+ >+ case ")": >+ if (state === State.Data && parenthesisUnclosedCount) >+ --parenthesisUnclosedCount; >+ break; >+ >+ case "/": >+ if (state === State.Data) { >+ if (i + 1 < length && value[i + 1] === "*") >+ state = State.Comment; >+ } >+ break; >+ >+ case "*": >+ if (state === State.Comment) { >+ if (i + 1 < length && value[i + 1] === "/") >+ state = State.Data; >+ } >+ break; >+ } >+ } >+ >+ let suffix = ""; >+ switch (state) { >+ case State.SingleQuoteString: >+ suffix = "'"; >+ break; >+ case State.DoubleQuoteString: >+ suffix = "\""; >+ break; >+ case State.Comment: >+ suffix = "*/"; >+ break; >+ } >+ >+ if (parenthesisUnclosedCount) >+ suffix += ")".repeat(parenthesisUnclosedCount); >+ >+ return suffix; >+ } >+ > // Public > > get values() >diff --git a/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js b/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js >index b727b04b590..9e6bc369e6e 100644 >--- a/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js >+++ b/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js >@@ -755,6 +755,11 @@ WI.SpreadsheetStyleProperty = class SpreadsheetStyleProperty extends WI.Object > > _valueCompletionDataProvider(prefix) > { >+ let value = this._valueTextField.valueWithoutSuggestion(); >+ let suffix = WI.CSSCompletions.fixUnbalancedCharacters(value); >+ if (suffix) >+ return [value + suffix]; >+ > let propertyName = this._nameElement.textContent.trim(); > return WI.CSSKeywordCompletions.forProperty(propertyName).startsWith(prefix); > } >diff --git a/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js b/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js >index 974264e5223..728a260ab90 100644 >--- a/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js >+++ b/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js >@@ -138,10 +138,10 @@ WI.SpreadsheetTextField = class SpreadsheetTextField > > completionSuggestionsSelectedCompletion(suggestionsView, selectedText = "") > { >- let prefix = this.valueWithoutSuggestion(); >- let completionPrefix = this._getCompletionPrefix(prefix); >+ let valueWithoutSuggestion = this.valueWithoutSuggestion(); > >- this.suggestionHint = selectedText.slice(completionPrefix.length); >+ let commonString = this._longestCommonPrefix(valueWithoutSuggestion, selectedText); >+ this.suggestionHint = selectedText.slice(commonString.length); > > this._reAttachSuggestionHint(); > >@@ -164,7 +164,7 @@ WI.SpreadsheetTextField = class SpreadsheetTextField > // newPrefix: 1px solid > // selectedText: rosybrown > let prefix = this.valueWithoutSuggestion(); >- let completionPrefix = this._getCompletionPrefix(prefix); >+ let completionPrefix = this._longestCommonPrefix(prefix, selectedText); > let newPrefix = prefix.slice(0, -completionPrefix.length); > > this._element.textContent = newPrefix + selectedText; >@@ -450,13 +450,24 @@ WI.SpreadsheetTextField = class SpreadsheetTextField > _getCompletionPrefix(prefix) > { > // For "border: 1px so|", we want to suggest "solid" based on "so" prefix. >- let match = prefix.match(/[a-z0-9()-]+$/i); >+ let match = prefix.match(/\b[a-z-]+$/i); > if (match) > return match[0]; > > return prefix; > } > >+ _longestCommonPrefix(a, b) >+ { >+ let bSlice = b.slice(0, a.length); >+ while (bSlice) { >+ if (a.endsWith(bSlice)) >+ return bSlice; >+ >+ bSlice = bSlice.slice(0, -1); >+ } >+ } >+ > _applyCompletionHint() > { > if (!this._completionProvider || !this.suggestionHint)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
nvasilyev
:
review-
nvasilyev
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 182523
:
333149
|
361144
|
361146
|
361363
|
361367
|
361521