Bug 147316 - Web Inspector: Autocomplete: Undo (Cmd+Z) doesn't work as expected
Summary: Web Inspector: Autocomplete: Undo (Cmd+Z) doesn't work as expected
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P1 Critical
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-07-26 22:58 PDT by Nikita Vasilyev
Modified: 2016-09-10 23:43 PDT (History)
8 users (show)

See Also:


Attachments
Animated GIF of the problem (83.14 KB, image/gif)
2015-07-26 22:58 PDT, Nikita Vasilyev
no flags Details
[Proposed] Patch (4.06 KB, patch)
2015-07-30 19:47 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
[Animated GIF] With the patch applied (99.73 KB, image/gif)
2015-07-31 18:08 PDT, Nikita Vasilyev
no flags Details
After Patch is Applied: CSS Rules Sidebar (94.58 KB, image/png)
2015-07-31 18:15 PDT, Devin Rousso
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Vasilyev 2015-07-26 22:58:18 PDT
Created attachment 257547 [details]
Animated GIF of the problem

The problem persists in all the places where autocomplete is available: console, styles panel, CSS resource, etc.

Steps:
1. type "window" in the console
2. Press Command Z

Actual:
> window|w
Note that Command Z didn't undo anything. On the contrary, it added an extra "w" at the end.


Expected:
> |
Console is empty, Command Z removed the entire word. This is how it works in Xcode and any other code editor I have encountered.
Comment 1 Radar WebKit Bug Importer 2015-07-26 22:58:43 PDT
<rdar://problem/22005227>
Comment 2 Devin Rousso 2015-07-30 19:47:51 PDT
Created attachment 257895 [details]
[Proposed] Patch

The reason for this is because the "replaceRange" call in "WebInspector.CodeMirrorCompletionController._applyCompletionHint" causes CodeMirror to add another history state, and that addition messes up the previous history states (each time the user changes the text, replaceRange is called, therefore interrupting the collating of history events).  Using "setUniqueBookmark" allows us to keep the history state accurate while also displaying the current completion.  There are some small setbacks (it does not have all of the styling as before), but the benefits of being able to undo nicely outweigh those drawbacks (in my opinion at least).
Comment 3 Nikita Vasilyev 2015-07-31 18:08:27 PDT
Created attachment 257984 [details]
[Animated GIF] With the patch applied

This works great!

(In reply to comment #2)
> Created attachment 257895 [details]
> [Proposed] Patch
> 
> ... There are some small setbacks (it does
> not have all of the styling as before)

Could you provide an example when this happens?
Comment 4 Devin Rousso 2015-07-31 18:15:48 PDT
Created attachment 257986 [details]
After Patch is Applied: CSS Rules Sidebar

(In reply to comment #3)
> Could you provide an example when this happens?

This issue also occurred in the CSS rules sidebar and the text there has a purplish color.  Since the completion hint text is now inside a text marker and not part of the text in the editor, it does not get any of the styling (notice that the "mar" is purple and the "gin: " is grey).
Comment 5 Nikita Vasilyev 2015-07-31 18:34:18 PDT
(In reply to comment #4)
> Created attachment 257986 [details]
> After Patch is Applied: CSS Rules Sidebar
> 
> (In reply to comment #3)
> > Could you provide an example when this happens?
> 
> This issue also occurred in the CSS rules sidebar and the text there has a
> purplish color.  Since the completion hint text is now inside a text marker
> and not part of the text in the editor, it does not get any of the styling
> (notice that the "mar" is purple and the "gin: " is grey).

The suggest hint used go be semi-transparent purple but now it's grey, I see.

(In reply to comment #2)
> ... There are some small setbacks (it does
> not have all of the styling as before), but the benefits of being able to
> undo nicely outweigh those drawbacks (in my opinion at least).

Agreed. I'd land this as it is and fix the suggest hint color later as a separate issue.
Comment 6 Timothy Hatcher 2015-07-31 20:45:13 PDT
Comment on attachment 257895 [details]
[Proposed] Patch

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

> Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js:251
> +        container.classList.add(WebInspector.CodeMirrorCompletionController.CompletionHintStyleClassName);

We could fix the color by mimicking the color based on the current token. But I think it is fine as grey.
Comment 7 WebKit Commit Bot 2015-07-31 21:15:56 PDT
Comment on attachment 257895 [details]
[Proposed] Patch

Clearing flags on attachment: 257895

Committed r187708: <http://trac.webkit.org/changeset/187708>
Comment 8 WebKit Commit Bot 2015-07-31 21:16:00 PDT
All reviewed patches have been landed.  Closing bug.