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

Implement inccommand #7416

Merged
merged 21 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
71ffd4f
Refactor search decorations, implement inccommand
adrsm108 Jan 17, 2022
e0aa82f
Accept empty string as value for :set
adrsm108 Jan 23, 2022
8a6f8a2
Merge branch 'VSCodeVim:master' into inccommand
adrsm108 Jan 23, 2022
e4c21a7
Escape icon codes in ex and search command line
adrsm108 Jan 23, 2022
bee3af5
Make :s command with c flag more interactive
adrsm108 Jan 23, 2022
90068df
Make :s command with c flag more interactive
adrsm108 Jan 23, 2022
2533bb7
Merge branch 'inccommand' of https://github.com/adrsm108/Vim into inc…
adrsm108 Jan 23, 2022
31ab174
Update tests to account for 'closed' property of Pattern
adrsm108 Jan 23, 2022
ec66266
Fix global state updating behavior
adrsm108 Jan 23, 2022
c215199
Add documentation
adrsm108 Jan 23, 2022
b6e55e1
Merge branch 'master' into inccommand
J-Fields Jan 26, 2022
1101d13
Merge branch 'master' into inccommand
J-Fields Jan 26, 2022
6d80817
Apply suggestions from code review
adrsm108 Jan 27, 2022
18a092f
Merge branch 'master' into inccommand
J-Fields Jan 29, 2022
1a6a314
Merge branch 'master' into inccommand
J-Fields Jan 31, 2022
aca1466
Merge branch 'master' into inccommand
J-Fields Feb 1, 2022
d0b0c82
Merge branch 'master' into inccommand
J-Fields Feb 1, 2022
0b4b6d5
Propagate changes to `inccommand` descriptions
adrsm108 Feb 4, 2022
45aea63
Merge branch 'master' into inccommand
adrsm108 Feb 4, 2022
3ecb9e0
Merge branch 'master' into inccommand
J-Fields Feb 6, 2022
9d06dbf
Merge branch 'master' into inccommand
J-Fields Feb 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ These settings are specific to VSCodeVim.
| vim.searchHighlightTextColor | Foreground color of non-current search matches | String | None |
| vim.searchMatchColor | Background color of current search match | String | `findMatchBackground` ThemeColor |
| vim.searchMatchTextColor | Foreground color of current search match | String | None |
| vim.substitutionColor | Background color of substitution text when `vim.inccommand` is enabled | String | "#50f01080" |
| vim.substitutionTextColor | Foreground color of substitution text when `vim.inccommand` is enabled | String | None |
| vim.startInInsertMode | Start in Insert mode instead of Normal Mode | Boolean | false |
| vim.useCtrlKeys | Enable Vim ctrl keys overriding common VS Code operations such as copy, paste, find, etc. | Boolean | true |
| vim.visualstar | In visual mode, start a search with `*` or `#` using the current selection | Boolean | false |
Expand Down Expand Up @@ -430,6 +432,7 @@ Configuration settings that have been copied from vim. Vim settings are loaded i
| vim.hlsearch | Highlights all text matching current search | Boolean | false |
| vim.ignorecase | Ignore case in search patterns | Boolean | true |
| vim.incsearch | Show the next match while entering a search | Boolean | true |
| vim.inccommand | Show the effects of the `:substitute` command while typing | String | `replace` |
| vim.joinspaces | Add two spaces after '.', '?', and '!' when joining or reformatting | Boolean | true |
| vim.leader | Defines key for `<leader>` to be used in key remappings | String | `\` |
| vim.maxmapdepth | Maximum number of times a mapping is done without resulting in a character to be used. This normally catches endless mappings, like ":map x y" with ":map y x". It still does not catch ":map g wg", because the 'w' is used before the next mapping is done. | Number | 1000 |
Expand Down
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@
"type": "string",
"markdownDescription": "Foreground color of the current match."
},
"vim.substitutionColor": {
"type": "string",
"markdownDescription": "Background color of substituted text when `#editor.inccommand#` is enabled. Uses `#editor.findMatchColor#` from current theme if undefined."
},
"vim.substitutionTextColor": {
"type": "string",
"markdownDescription": "Foreground color of substituted text when `#editor.inccommand#` is enabled."
},
"vim.highlightedyank.enable": {
"type": "boolean",
"description": "Enable highlighting when yanking.",
Expand Down Expand Up @@ -787,6 +795,21 @@
"description": "Show all matches of the most recent search pattern.",
"default": false
},
"vim.inccommand": {
"type": "string",
"markdownDescription": "Show the effects of the `:substitute` command as you type.",
"default": "replace",
"enum": [
"",
"append",
"replace"
],
"enumDescriptions": [
"Don't show substitutions",
"Show substitutions after matched text",
"Replace matched text with substitutions"
]
},
"vim.incsearch": {
"type": "boolean",
"markdownDescription": "Show where a `/` or `?` search matches as you type it.",
Expand Down
47 changes: 37 additions & 10 deletions src/cmd_line/commandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ import { IndexedPosition, IndexedRange, SearchState } from '../state/searchState
import { getWordLeftInText, getWordRightInText, WordType } from '../textobject/word';
import { CommandShowCommandHistory, CommandShowSearchHistory } from '../actions/commands/actions';
import { SearchDirection } from '../vimscript/pattern';
import { reportSearch } from '../util/statusBarTextUtils';
import { Position, ExtensionContext, window } from 'vscode';
import { reportSearch, escapeCSSIcons } from '../util/statusBarTextUtils';
import {
SearchDecorations,
ensureVisible,
getDecorationsForSearchMatchRanges,
} from '../util/decorationUtils';
import { Position, ExtensionContext, window, DecorationOptions, Range } from 'vscode';
import { globalState } from '../state/globalState';
import { scrollView } from '../util/util';
import { ExCommand } from '../vimscript/exCommand';
import { LineRange } from '../vimscript/lineRange';
import { RegisterCommand } from './commands/register';
import { SubstituteCommand } from './commands/substitute';

export abstract class CommandLine {
public cursorIndex: number;
Expand Down Expand Up @@ -53,6 +59,8 @@ export abstract class CommandLine {

public abstract getHistory(): HistoryFile;

public abstract getDecorations(vimState: VimState): SearchDecorations | undefined;

/**
* Called when `<Enter>` is pressed
*/
Expand Down Expand Up @@ -211,9 +219,11 @@ export class ExCommandLine extends CommandLine {
}

public display(cursorChar: string): string {
return `:${this.text.substring(0, this.cursorIndex)}${cursorChar}${this.text.substring(
this.cursorIndex
)}`;
return escapeCSSIcons(
`:${this.text.substring(0, this.cursorIndex)}${cursorChar}${this.text.substring(
this.cursorIndex
)}`
);
}

public get text(): string {
Expand All @@ -237,6 +247,13 @@ export class ExCommandLine extends CommandLine {
return undefined;
}

public getDecorations(vimState: VimState): SearchDecorations | undefined {
return this.command instanceof SubstituteCommand &&
vimState.currentMode === Mode.CommandlineInProgress
? this.command.getSubstitutionDecorations(vimState, this.lineRange)
: undefined;
}

public getHistory(): HistoryFile {
return ExCommandLine.history;
}
Expand Down Expand Up @@ -381,11 +398,12 @@ export class SearchCommandLine extends CommandLine {
}

public display(cursorChar: string): string {
return `${
this.searchState.direction === SearchDirection.Forward ? '/' : '?'
}${this.text.substring(0, this.cursorIndex)}${cursorChar}${this.text.substring(
this.cursorIndex
)}`;
return escapeCSSIcons(
`${this.searchState.direction === SearchDirection.Forward ? '/' : '?'}${this.text.substring(
0,
this.cursorIndex
)}${cursorChar}${this.text.substring(this.cursorIndex)}`
);
}

public get text(): string {
Expand Down Expand Up @@ -440,6 +458,15 @@ export class SearchCommandLine extends CommandLine {
);
}

public getDecorations(vimState: VimState): SearchDecorations | undefined {
return getDecorationsForSearchMatchRanges(
this.searchState.getMatchRanges(vimState),
configuration.incsearch && vimState.currentMode === Mode.SearchInProgressMode
? this.getCurrentMatchRange(vimState)?.index
: undefined
);
}

public async run(vimState: VimState): Promise<void> {
await vimState.setCurrentMode(this.previousMode);

Expand Down
2 changes: 1 addition & 1 deletion src/cmd_line/commands/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type SetOperation =
};

const optionParser = regexp(/[a-z]+/);
const valueParser = regexp(/\S+/);
const valueParser = regexp(/\S*/);
const setOperationParser: Parser<SetOperation> = whitespace
.then(
alt<SetOperation>(
Expand Down
Loading