Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inccommand: fix for wrapping of large string in preview mode #8283

Closed
wants to merge 1 commit into from

Conversation

nimitbhardwaj
Copy link
Contributor

When entering a large string in substitute command when set inccommand=nosplit is enabled, the string wraps around the single line. This was due to the condition that in Preview mode, we need a kind of behaviour where the DOCMD_NOWAIT is not completely necessary because there is change in the size of the cmdlilne, but we don't need to wait for the return, so ++no_wait_return was not necessary.

@@ -577,6 +577,14 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
++RedrawingDisabled;
did_inc = TRUE;
}
if (State & CMDPREVIEW) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also add the condition in the above if stmt to check for CMDPREVIEW, and remove the DOCMD_NOWAIT from the part where this function will be called, for the case of previewable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is need to shorten the code that would be good

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the above would be better. why did you removed ++no_wait_return ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this because, I thought that for the completion of the preview command, there is finally need of a return, as told on Gitter, it NOWAIT was for hiding the Press Enter... error message.
Mostly this was I think work was of hit and trial, how I reached this, I had the idea that the code that will execute the Inccommand, so I tried to remove the DOCMD_NOWAIT it worked a little bit, but just give the notice Press Return or another key ..., so to remove this msg, I found the code what extra will happen if DOCMD_NOWAIT flag is given, I found out, and tried to hack code there, as described above using some common sense of the inccommands and a little bit about the functions which will be triggered by reading the comments, I had a lucky guess.

@marvim marvim added the RFC label Apr 15, 2018
@nimitbhardwaj nimitbhardwaj force-pushed the longSubstitute branch 2 times, most recently from 0d341b5 to 745f904 Compare April 16, 2018 11:12
@nimitbhardwaj
Copy link
Contributor Author

nimitbhardwaj commented Apr 17, 2018

What about the tests of this PR, means it was a bug fix, how should i add tests.

@@ -1911,7 +1911,7 @@ static int command_line_changed(CommandLineState *s)
// - Immediately undo the effects.
State |= CMDPREVIEW;
emsg_silent++; // Block error reporting as the command may be incomplete
do_cmdline(ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_NOWAIT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we keep this and instead add State & CMDPREVIEW as an alternative in the enclosing if-statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to think of it as I reach room, now in class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By keeping DOCMD_NOWAIT, it means that the if part in ex_docmd.c will not work, I want that the if part should work, but only no_wait_return should not be incremented, if I have to edit it, the condition in if will become so messy, and according to my personal opinion, I don't like to read a messy, complicated and big condition, so I put this like the way.

Other alternative which I think that was good, was making a separate if condition for State & CMDPREVIEW but according to @justinmk its also not too better, so this option was left, which I thought was acceptable.
What are the views on it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is a no-wait state, just like async and <Cmd> commands in cmdline mode. Just having this flag silently missing when it is expected is also messy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okk, then its an issue, then making the condition edit is better.

@bfredl
Copy link
Member

bfredl commented Apr 17, 2018

As this is a visual glitch it should use a screen test. Follow the pattern of the existing screen tests in ui/inccommand_spec.lua.

@nimitbhardwaj
Copy link
Contributor Author

Ok

@nimitbhardwaj
Copy link
Contributor Author

For the time you analyze it further, I create the test for the this PR

@nimitbhardwaj nimitbhardwaj force-pushed the longSubstitute branch 2 times, most recently from 4c4f4ac to f17729d Compare April 20, 2018 08:08
@nimitbhardwaj nimitbhardwaj changed the title [RFC] Fix for wrapping of large string in preview mode [RDY] Fix for wrapping of large string in preview mode Apr 21, 2018
@marvim marvim added RDY and removed RFC labels Apr 21, 2018
@@ -568,14 +568,19 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
* from a script or when being called recursive (e.g. for ":e
* +command file").
*/
if (!(flags & DOCMD_NOWAIT) && !recursive) {
bool isPreview = (State & CMDPREVIEW) == 0 ? false : true;
Copy link
Member

@justinmk justinmk Apr 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(State & CMDPREVIEW) == 0 evaluates to boolean, no need to use a ternary. !!(State & CMDPREVIEW) is also a common idiom.

Also we don't use camelCase , so name would be is_preview.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okk, !!(State & CMDPREVIEW) is good, new style for me. 👍

@justinmk
Copy link
Member

The AppVeyor failure looks related to this change.

[  ERROR   ] C:/projects/neovim/test/functional\ui\inccommand_spec.lua @ 135: :substitute, 'inccommand' preserves listed buffers (:ls)
test\functional\ui\screen.lua:307: Row 1 did not match.
Expected:
  |*{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |:ls                           |
  |  1 %a + "[No Name]"          |
  |          line 1              |
  |{13:Press ENTER or type command to}|
  |{13: continue}^                     |
Actual:
  |*^BAC                           |
  |{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |{15:~                             }|
  |                              |
To print the expect() call that would assert the current screen state, use

Maybe the test just needs to be adjusted. Need to look at the test, understand what it's doing, and decide if the change from this PR caused a bug, or if the test just needs to be a adjusted.

if (!isPreview) {
// For execution of a preview command we have to wait for a return
// key, but we don't want the message for it pop out
no_wait_return++; // don't wait for return until finished
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we don't want the message for it pop out

If we don't want to wait, why no_wait_return++ for !isPreview ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, may be wrong msg, I think I was thinking some otherthing, I also change it

@justinmk
Copy link
Member

The quickbuild BSD failure looks related:

05:06:52,403 INFO  - not ok 2743 - :substitute, inccommand=split shows correct line numbers with many lines
05:06:52,403 INFO  - # test/functional/ui/inccommand_spec.lua @ 1023
05:06:52,403 INFO  - # Failure message: ./test/functional/ui/screen.lua:307: Row 1 did not match.
05:06:52,403 INFO  - # Expected:
05:06:52,403 INFO  - #   |*BBo lines                     |
05:06:52,403 INFO  - #   |Inc substitution on           |
05:06:52,403 INFO  - #   |{12:X}o lines                      |
05:06:52,403 INFO  - #   |Inc substitution on           |
05:06:52,403 INFO  - #   |{12:X}o lines                      |
05:06:52,403 INFO  - #   |{11:[No Name] [+]                 }|
05:06:52,403 INFO  - #   ||1001| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1003| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1005| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1007| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1009| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1011| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1013| {12:X}o lines               |
05:06:52,403 INFO  - #   |{10:[Preview]                     }|
05:06:52,403 INFO  - #   |:%s/tw/X^                      |
05:06:52,403 INFO  - # Actual:
05:06:52,403 INFO  - #   |*Inc substitution on           |
05:06:52,403 INFO  - #   |BBo lines                     |
05:06:52,403 INFO  - #   |Inc substitution on           |
05:06:52,403 INFO  - #   |{12:X}o lines                      |
05:06:52,403 INFO  - #   |Inc substitution on           |
05:06:52,403 INFO  - #   |{11:[No Name] [+]                 }|
05:06:52,403 INFO  - #   ||1001| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1003| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1005| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1007| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1009| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1011| {12:X}o lines               |
05:06:52,403 INFO  - #   ||1013| {12:X}o lines               |
05:06:52,403 INFO  - #   |{10:[Preview]                     }|
05:06:52,403 INFO  - #   |:%s/tw/X^                      |
05:06:52,403 INFO  - #-

@justinmk justinmk changed the title [RDY] Fix for wrapping of large string in preview mode [RFC] Fix for wrapping of large string in preview mode Apr 21, 2018
@marvim marvim added RFC and removed RDY labels Apr 21, 2018
@nimitbhardwaj
Copy link
Contributor Author

I correct em

@nimitbhardwaj
Copy link
Contributor Author

By the way why this error occurs, I didn't changed the code of that part, I even didn't touch the code for that describe i.e. of substitute, inccommand=split I put my test in describe of inccommand=nosplit

@nimitbhardwaj
Copy link
Contributor Author

Perhaps I should make the commit again and test if that error persists, and if persists, I will try by removing the test.

@nimitbhardwaj
Copy link
Contributor Author

Lets have a try on this

@nimitbhardwaj
Copy link
Contributor Author

nimitbhardwaj commented Apr 21, 2018

Yes error occurs, this may be due to my change in src, I try what can I do, I am sure, that error didn't occur previously, some changes occur after my work

This is surly now I think the fault of my code, it works for this case, for inccommand=nosplit but I think for inccommand=split it is not correct, I try to find some way to deal with it, I hope to try it later, this is week of my exams
For the other time, if there is some error in my other PRs please tell it to me too, it the error is not so big I would deal it, if it it would require some research, I would make it pending for now

@justinmk justinmk added the gsoc community: Google Summer of Code project label Apr 24, 2018
@justinmk justinmk changed the title [RFC] Fix for wrapping of large string in preview mode inccommand: fix for wrapping of large string in preview mode Dec 9, 2019
@justinmk justinmk removed the RFC label Jan 28, 2020
@justinmk
Copy link
Member

Seems to be fixed on b7084fe

image

'inccommand' impl changed with #18194

@justinmk justinmk closed this Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gsoc community: Google Summer of Code project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants