Bug 194796

Summary: Web Inspector: Styles: Control-Space should force completion
Product: WebKit Reporter: Nikita Vasilyev <nvasilyev>
Component: Web InspectorAssignee: Nikita Vasilyev <nvasilyev>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, hi, inspector-bugzilla-changes, mattbaker, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
mattbaker: review-
[Video] With patch applied
none
Patch
none
Patch
mattbaker: review+
Patch for landing none

Description Nikita Vasilyev 2019-02-18 15:29:26 PST
Pressing Control-Space should show completion popover, even if the value is empty. This is how it works in Xcode, Chrome DevTools, and just about every code editor.
Comment 1 Radar WebKit Bug Importer 2019-02-18 15:30:24 PST
<rdar://problem/48180822>
Comment 2 Nikita Vasilyev 2019-02-18 15:32:19 PST
Created attachment 362349 [details]
Patch
Comment 3 Nikita Vasilyev 2019-02-18 15:32:40 PST
Created attachment 362350 [details]
[Video] With patch applied
Comment 4 Matt Baker 2019-02-18 15:36:34 PST
One thing I find really annoying is pressing Escape in the TextEditor shows the completion popover, for a file that is probably read-only, when it would be so much better to focus the Quick Console instead.

If control-space is a common shortcut for showing autocompletion, can we free up escape for this?
Comment 5 Nikita Vasilyev 2019-02-18 15:41:03 PST
(In reply to Matt Baker from comment #4)
> One thing I find really annoying is pressing Escape in the TextEditor shows
> the completion popover, for a file that is probably read-only, when it would
> be so much better to focus the Quick Console instead.

We shouldn't autocomplete for read-only resources, period. 

> 
> If control-space is a common shortcut for showing autocompletion, can we
> free up escape for this?

I think it makes sense. I'd prefer to do it as a separate patch since it's unrelated to the styles sidebar.
Comment 6 Matt Baker 2019-02-18 15:47:48 PST
(In reply to Matt Baker from comment #4)
> One thing I find really annoying is pressing Escape in the TextEditor shows
> the completion popover, for a file that is probably read-only, when it would
> be so much better to focus the Quick Console instead.

Actually it's only an issue for local files. Also I couldn't ever get the focus to jump to the Quick Console, so maybe that was never a thing.

> If control-space is a common shortcut for showing autocompletion, can we
> free up escape for this?

I think the case we actually want to consider is autocomplete in the Quick Console. Escape is the shortcut for both show/hide console drawer, and show/dismiss autocomplete. I think we should only use control-space to show autocomplete.

What do you think?
Comment 7 Matt Baker 2019-02-18 15:48:23 PST
(In reply to Nikita Vasilyev from comment #5)
> (In reply to Matt Baker from comment #4)
> > One thing I find really annoying is pressing Escape in the TextEditor shows
> > the completion popover, for a file that is probably read-only, when it would
> > be so much better to focus the Quick Console instead.
> 
> We shouldn't autocomplete for read-only resources, period. 
> 
> > 
> > If control-space is a common shortcut for showing autocompletion, can we
> > free up escape for this?
> 
> I think it makes sense. I'd prefer to do it as a separate patch since it's
> unrelated to the styles sidebar.

Makes sense!
Comment 8 Matt Baker 2019-02-19 20:37:46 PST
Comment on attachment 362349 [details]
Patch

r- for now, because completions for property values are currently broken, making this difficult to review.

The completions popover is no longer shown when tabbing to a new property value from a property name. This regressed in https://webkit.org/b/193605. I think it makes sense to fix the behavior as part of this patch, since they are so closely related.
Comment 9 Matt Baker 2019-02-19 20:44:06 PST
Comment on attachment 362349 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362349&action=review

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js:372
> +    _updateCompletions(forceCompletions = false)

It would be great if we could avoid passing this flag across so many functions.
Comment 10 Nikita Vasilyev 2019-02-22 14:00:19 PST
Created attachment 362761 [details]
Patch
Comment 11 Nikita Vasilyev 2019-02-22 14:00:42 PST
(In reply to Matt Baker from comment #8)
> Comment on attachment 362349 [details]
> Patch
> 
> r- for now, because completions for property values are currently broken,
> making this difficult to review.
> 
> The completions popover is no longer shown when tabbing to a new property
> value from a property name. This regressed in https://webkit.org/b/193605. I
> think it makes sense to fix the behavior as part of this patch, since they
> are so closely related.

Fixed!
Comment 12 Nikita Vasilyev 2019-02-22 14:07:19 PST
(In reply to Matt Baker from comment #9)
> Comment on attachment 362349 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=362349&action=review
> 
> > Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js:372
> > +    _updateCompletions(forceCompletions = false)
> 
> It would be great if we could avoid passing this flag across so many
> functions.

I don't think I can avoid it.

We don't show completion popover for empty CSS property names (e.g. when creating a new property). I think it makes sense because at the top of the list are obscure -apple- and -epub- properties.

I'm fine with showing completion popover for empty property names after this bug lands: Bug 156271 - Web Inspector: CSS autocomplete: suggestion hint should be the most commonly used property and not the alphabetically first one.
Comment 13 Devin Rousso 2019-02-25 17:32:35 PST
Comment on attachment 362761 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362761&action=review

> Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js:268
> +        if (prefix === "")

NIT: `!prefix`.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:712
> +    _nameCompletionDataProvider(prefix, forceCompletion = false)

I'd prefer you put this inside an optional `options` object and rename it to a positive.

    _nameCompletionDataProvider(prefix, options = {})
        let completions = null;
        if (!prefix && options.allowEmptyPrefix)
            completions = WI.CSSCompletions.cssNameCompletions.values;
        else
            completions = WI.CSSCompletions.cssNameCompletions.startsWith(prefix);

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:716
> +        if (!prefix && forceCompletion)
> +            completions = WI.CSSCompletions.cssNameCompletions.values;

If `forceCompletion` is `false`, both of these paths will have the same effect.  If we show all values when `prefix` is empty, all we really need to do is force the completion popover to appear when ⌃-Space is pressed.  `forceCompletion` is unnecessary.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:719
> +

NIT: unnecessary newline.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:-750
> -            completions: WI.CSSKeywordCompletions.forProperty(propertyName).startsWith(prefix)

Why was this changed?  Having it inline is fine.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js:281
> +        if (event.ctrlKey && event.code === "Space") {

We should decide on <https://webkit.org/b/192947> before doing this.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js:378
> +        let {completions, prefix} = this._completionProvider(valueWithoutSuggestion, forceCompletions);

You also need to update `WI.SpreadsheetStyleProperty.prototype._valueCompletionDataProvider` for this.
Comment 14 Nikita Vasilyev 2019-02-25 17:51:25 PST
Comment on attachment 362761 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362761&action=review

>> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:716
>> +            completions = WI.CSSCompletions.cssNameCompletions.values;
> 
> If `forceCompletion` is `false`, both of these paths will have the same effect.  If we show all values when `prefix` is empty, all we really need to do is force the completion popover to appear when ⌃-Space is pressed.  `forceCompletion` is unnecessary.

"If `forceCompletion` is `false`, both of these paths will have the same effect." — no, they won't.
We don't show completion popover for empty CSS property names (e.g. when creating a new property).
Comment 15 Devin Rousso 2019-02-25 18:44:32 PST
Comment on attachment 362761 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362761&action=review

>>> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:716
>>> +            completions = WI.CSSCompletions.cssNameCompletions.values;
>> 
>> If `forceCompletion` is `false`, both of these paths will have the same effect.  If we show all values when `prefix` is empty, all we really need to do is force the completion popover to appear when ⌃-Space is pressed.  `forceCompletion` is unnecessary.
> 
> "If `forceCompletion` is `false`, both of these paths will have the same effect." — no, they won't.
> We don't show completion popover for empty CSS property names (e.g. when creating a new property).

Ah, I missed the part where `_acceptEmptyPrefix` gets set.

Why is it that we don't want to show a completion for an empty property name?  Is it just because there are a lot of CSS properties?  If we're adding a keyboard shortcut to force completions, but only for values, that seems a bit strict.
Comment 16 Nikita Vasilyev 2019-02-25 18:52:53 PST
Because this is what it shows for empty property names:

    -apple-color-filter
    -apple-pay-button-style
    -apple-pay-button-type
    -apple-trailing-word
    -epub-caption-side
    -epub-hyphens
    -epub-text-combine
    -epub-text-emphasis
    -epub-text-emphasis-color
    -epub-text-emphasis-style
    -epub-text-orientation

I'm to show completions for empty property names once we land your patch to show the most commonly used properties first.
Comment 17 Nikita Vasilyev 2019-02-26 17:19:26 PST
Created attachment 363042 [details]
Patch
Comment 18 Nikita Vasilyev 2019-02-27 12:13:55 PST
(In reply to Nikita Vasilyev from comment #16)
> I'm to show completions for empty property names once we land your patch to
> show the most commonly used properties first.

*I'm fine with showing
Comment 19 Matt Baker 2019-02-28 12:24:29 PST
(In reply to Nikita Vasilyev from comment #16)
> Because this is what it shows for empty property names:
> 
>     -apple-color-filter
>     -apple-pay-button-style
>     -apple-pay-button-type
>     -apple-trailing-word
>     -epub-caption-side
>     -epub-hyphens
>     -epub-text-combine
>     -epub-text-emphasis
>     -epub-text-emphasis-color
>     -epub-text-emphasis-style
>     -epub-text-orientation
> 
> I'm to show completions for empty property names once we land your patch to
> show the most commonly used properties first.

I'm not sure we want to do this. The user probably isn't adding a new CSS property unless they have at least an idea of what the property is, even if they can't remember, say, how to spell it. Sorting the list by commonly used properties will surface useful properties some of the time, but it is still distracting at best IMO.
Comment 20 Matt Baker 2019-02-28 12:35:18 PST
Comment on attachment 363042 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=363042&action=review

r=me

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js:379
> +        const options = {allowEmptyPrefix: forceCompletions};

This can be inlined:

let {completions, prefix} = this._completionProvider(valueWithoutSuggestion, {allowEmptyPrefix: forceCompletions});
Comment 21 Nikita Vasilyev 2019-02-28 12:41:13 PST
Created attachment 363252 [details]
Patch for landing
Comment 22 WebKit Commit Bot 2019-02-28 13:19:30 PST
Comment on attachment 363252 [details]
Patch for landing

Clearing flags on attachment: 363252

Committed r242218: <https://trac.webkit.org/changeset/242218>
Comment 23 WebKit Commit Bot 2019-02-28 13:19:32 PST
All reviewed patches have been landed.  Closing bug.
Comment 24 Nikita Vasilyev 2019-03-14 13:56:43 PDT
*** Bug 182471 has been marked as a duplicate of this bug. ***