johtela / vscode-modaledit

Configurable Modal Editing in VS Code
https://johtela.github.io/vscode-modaledit/docs/README.html
Other
89 stars 8 forks source link

[Bug?] Search doesn't search entire file #8

Closed brillout closed 3 years ago

brillout commented 4 years ago

If I make a forward-search at the end of the file then I won't get any result because forward search only searches from current line to end of file. It doesn't consider any previous lines.

In my experience this is unusual.

What do you think of making modaledit.search always search the entire file instead?

johtela commented 4 years ago

The design of the command is such that it searches from the cursor position forwards by default. To search backwards, the backwards parameter can be set. So, I would not consider this a bug.

Nevertheless, I can see the use of being able to search the entire file. I guess the cleanest solution would be to add a new parameter that wraps around when the end or beginning of the file is encountered. Is that something you could live with?

brillout commented 4 years ago

Yes a parameter would be fantastic.

The design of the command is such that it searches from the cursor position forwards by default. To search backwards, the backwards parameter can be set. So, I would not consider this a bug.

Yes I did suspect that it was a design decision on your part :-).

I can't speak for others but I'd guess that most people would expect a search to go through the entire file. E.g. vscode's Ctrl + F search does that. Maybe I'd set the parameter to true by default.

Anyways I'm already happy if I can opt-in with a parameter.

brillout commented 4 years ago

Yes I did suspect that it was a design decision on your part :-).

Btw. I'm curious: why did you design it that way?

johtela commented 4 years ago

I chose the design to allow using the same command for jumping to a specific character(s). Like with Vim's f and t commands:

fX  to next 'X' after cursor, in the same line (X is any character)
FX  to previous 'X' before cursor (f and F put the cursor on X)
tX  til next 'X' (similar to above, but cursor is before X)
TX  til previous 'X'

If you always want to start the find from the beginning there is an easy workaround: use the cursorTop command to move the cursor to the beginning before starting the search. Like this:

    [
        "cursorTop",
        {
            "command": "modaledit.search",
            "args": {
                "caseSensitive": true
            }
        }
]
johtela commented 3 years ago

In version 2.0 there is a new parameter wrapAround for the search command. It jumps to top or bottom depending on the search direction when the search string is not found.