vimperator / vimperator-labs

Vimperator
http://vimperator.org
Other
1.19k stars 195 forks source link

Command prompt selection is (sometimes) cleared for no reason #259

Open mina86 opened 9 years ago

mina86 commented 9 years ago

I have the following two bindings:

noremap d O<Home><Right><Right><Right><Right><Right><S-End>
noremap D T<Home><Right><Right><Right><Right><Right><Right><Right><Right><S-End>

The idea is to put URL of the current tab on the command prompt but select it such that if I just start typing, the URL is replaced with whatever I enter. This sometimes works but sometimes the selection is cleared before I have a chance to type anything. I can see the mapping working, i.e. the URL blinks as selected, but then something clears the selection.

timss commented 8 years ago

This seems to be due to a race condition of sorts when using O or T together with command line completion.

By default it'll complete using complete=sl (search engines, keywords, location bar). The selection is cleared because O or T seems to complete the current URL.

If you use set complete= and your mapping, it works because no completion is done.

This is such an edge case that adding logic to circumvent this in Vimperator wouldn't make much sense. Instead, you could try to create a function and/or fancy map that toggles completion on/off. Unfortunately I'm not able to think of anything else right now.

SammysHP commented 8 years ago

I'd like to add some notes to this issue and ask to reopen it. For a long time I am annoyed by the lost of selection when using O and T. From the beginning I know that the reason for this is the completion. Today I experimented a little bit and found an anomaly:

Scenario 1

  1. Open a webpage and press O: The URL is shown and the completer starts to search for completions.
  2. While the completer is still working, press Shift+ to select the last characters.
  3. Every time the completer's timer or whatever generates a result the selection is lost and the caret is set to the end of the line.

Scenario 2

  1. Open a webpage and press O, same as above.
  2. While the completer is still working, press to move one character to the left, then press Shift+ to select some characters.
  3. The completer does its work, but the selection and caret position is preserved!

Scenario 3

  1. Open the :open commandline by pressing o.
  2. Start to type something that might be found by the completer.
  3. While the completer is still working, press Shift+ to select the last characters.
  4. The completer does its work, but the selection and caret position is preserved!

Conclusion

Somehow the completion is invoked differently when using O or T. Also it does only happen when the caret is at the end of the commandline.

This seems to be a bug that can be fixed (as it already works in other situations). I had a quick look into the code, but haven't found the correct place yet.

Update: Maybe I was able to reduce the issue to a specific case: The lost of the selection occurs only if the completion starts at the beginning, e.g.

  1. Press o and paste https://github.com/vimperator/vimperator-labs/
  2. The selection is lost.

 

  1. Press o and paste ttps://github.com/vimperator/vimperator-labs/
  2. Nothing is completed. (Why?)

 

  1. Press o and paste github.com/vimperator/vimperator-labs/
  2. The selection is preserved!

But I'm not completely sure because timing is really important and often the completer is too fast.

SammysHP commented 8 years ago

I spent some hours (well, many hours) tracing this bug and finally found the reason. It is in common/content/commandline.js#L1281. I assume that the caret position / selection is somehow lost when the caret is at the last position when insertNode() is called.

I tried to trace it further, but this is hardcore low-level XUL stuff (hey, didn't they say that XUL will be removed sometime in the future?) and I failed at some point.

This might be of some help because Google failed to find any documentation: http://doxygen.db48x.net/mozilla/html/interfacensIEditor.html

SammysHP commented 7 years ago

Yesterday I found a situation where this issue still occurs. Please reopen.