-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ReplaceState into its own class.
- Loading branch information
Showing
4 changed files
with
45 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters