diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 56f09434546..8488bece790 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -1,5 +1,6 @@ -import { VimState, ReplaceState } from './../mode/modeHandler'; +import { VimState } from './../mode/modeHandler'; import { SearchState, SearchDirection } from './../state/searchState'; +import { ReplaceState } from './../state/replaceState'; import { VisualBlockMode } from './../mode/modeVisualBlock'; import { ModeName } from './../mode/mode'; import { VisualBlockInsertionType } from './../mode/modeVisualBlock'; diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 4a53c586be7..5adaa22d499 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -36,6 +36,7 @@ import { PairMatcher } from './../matching/matcher'; import { Globals } from '../../src/globals'; import { allowVSCodeToPropagateCursorUpdatesAndReturnThem } from './../util'; import { SearchState } from './../state/searchState'; +import { ReplaceState } from './../state/replaceState'; export class ViewChange { public command: string; @@ -200,36 +201,6 @@ export class VimState { public whatILastSetTheSelectionTo: vscode.Selection; } -export class ReplaceState { - /** - * The location of the cursor where you begun to replace characters. - */ - public replaceCursorStartPosition: Position; - - public originalChars: string[] = []; - - /** - * The characters the user inserted in replace mode. Useful for when - * we repeat a replace action with . - */ - public newChars: string[] = []; - - /** - * Number of times we're going to repeat this replace action. - */ - public timesToRepeat: number; - - constructor(startPosition: Position, timesToRepeat: number = 1) { - this.replaceCursorStartPosition = startPosition; - this.timesToRepeat = timesToRepeat; - - let text = TextEditor.getLineAt(startPosition).text.substring(startPosition.character); - for (let [key, value] of text.split("").entries()) { - this.originalChars[key + startPosition.character] = value; - } - } -} - /** * The RecordedState class holds the current action that the user is * doing. Example: Imagine that the user types: diff --git a/src/state/replaceState.ts b/src/state/replaceState.ts new file mode 100644 index 00000000000..349f032fd97 --- /dev/null +++ b/src/state/replaceState.ts @@ -0,0 +1,35 @@ +import { Position } from './../motion/position'; +import { TextEditor } from './../textEditor'; + +/** + * State involved with entering Replace mode (R). + */ +export class ReplaceState { + /** + * The location of the cursor where you begun to replace characters. + */ + public replaceCursorStartPosition: Position; + + public originalChars: string[] = []; + + /** + * The characters the user inserted in replace mode. Useful for when + * we repeat a replace action with . + */ + public newChars: string[] = []; + + /** + * Number of times we're going to repeat this replace action. + */ + public timesToRepeat: number; + + constructor(startPosition: Position, timesToRepeat: number = 1) { + this.replaceCursorStartPosition = startPosition; + this.timesToRepeat = timesToRepeat; + + let text = TextEditor.getLineAt(startPosition).text.substring(startPosition.character); + for (let [key, value] of text.split("").entries()) { + this.originalChars[key + startPosition.character] = value; + } + } +} diff --git a/src/state/searchState.ts b/src/state/searchState.ts index 3db99954f3c..533f694c63e 100644 --- a/src/state/searchState.ts +++ b/src/state/searchState.ts @@ -8,14 +8,18 @@ export enum SearchDirection { Backward = -1 } +/** + * State involved with beginning a search (/). + */ export class SearchState { private static readonly MAX_SEARCH_RANGES = 1000; private static specialCharactersRegex: RegExp = /[\-\[\]{}()*+?.,\\\^$|#\s]/g; + private _matchRanges: vscode.Range[] = []; + /** * Every range in the document that matches the search string. */ - private _matchRanges: vscode.Range[] = []; public get matchRanges(): vscode.Range[] { return this._matchRanges; } @@ -51,7 +55,8 @@ export class SearchState { this._matchesDocVersion = TextEditor.getDocumentVersion(); this._matchRanges = []; - /* Decide whether the search is case sensitive. + /* + * Decide whether the search is case sensitive. * If ignorecase is false, the search is case sensitive. * If ignorecase is true, the search should be case insensitive. * If both ignorecase and smartcase are true, the search is case sensitive only when the search string contains UpperCase character.