This repository was archived by the owner on Dec 27, 2020. It is now read-only.
Open
Conversation
naturetime10
suggested changes
Aug 31, 2020
Comment on lines
1
to
+10
| export function insert<T>(arr: T[], index: number, slice: T[]): T[] { | ||
| return [...arr.slice(0, index), ...slice, ...arr.slice(index)]; | ||
| } | ||
|
|
||
| export function remove<T>(arr: T[], idx: number, count: number = 1): T[] { | ||
| return [ | ||
| ...arr.slice(0, idx), | ||
| ...arr.slice(idx + count) | ||
| ]; | ||
| } No newline at end of file |
Member
There was a problem hiding this comment.
We are going to use those helpers over & over again. Let's include unit tests for them so that we are confident they are working correctly when dealing with complexities for the actions.
| } | ||
| }, | ||
| { | ||
| name: 'should delete 1 character at cursor position and should delete the segment when segment is empty', |
Member
There was a problem hiding this comment.
Suggested change
| name: 'should delete 1 character at cursor position and should delete the segment when segment is empty', | |
| name: 'should delete 1 character and the empty segment', |
| } | ||
| }, | ||
| { | ||
| name: 'should delete multiple characters at cursor selection', |
Member
There was a problem hiding this comment.
Suggested change
| name: 'should delete multiple characters at cursor selection', | |
| name: 'should delete all selected characters in a single segment', |
|
|
||
| const testCases: ITestCase[] = [ | ||
| { | ||
| name: 'should delete 1 character at cursor position', |
Member
There was a problem hiding this comment.
Suggested change
| name: 'should delete 1 character at cursor position', | |
| name: 'should delete 1 character in a single segment', |
| } | ||
| }, | ||
| { | ||
| name: 'should delete multiple characters at cursor selection among different start/end segment', |
Member
There was a problem hiding this comment.
Suggested change
| name: 'should delete multiple characters at cursor selection among different start/end segment', | |
| name: 'should delete multiple selected characters across 2 segments', |
| {}, | ||
| endSegment, | ||
| { | ||
| // to remove the single char at the cursor |
Member
There was a problem hiding this comment.
Suggested change
| // to remove the single char at the cursor |
| let startIndex = startSegment.index; | ||
| let endIndex = endSegment.index; | ||
| if (startSegment.content.length === 0) { | ||
| startIndex = startIndex - 1; |
Member
There was a problem hiding this comment.
Suggested change
| startIndex = startIndex - 1; | |
| startIndex--; |
| startIndex = startIndex - 1; | ||
| } | ||
| if (endSegment.content.length === 0) { | ||
| endIndex = endIndex + 1; |
Member
There was a problem hiding this comment.
Suggested change
| endIndex = endIndex + 1; | |
| endIndex++; |
|
|
||
| if (endIndex - startIndex - 1 > 0) { | ||
| newSegments = remove<ISegment>(newSegments, startIndex + 1, endIndex - startIndex - 1); | ||
| newSegments = this.rematchIndex(newSegments); |
Member
There was a problem hiding this comment.
Suggested change
| newSegments = this.rematchIndex(newSegments); | |
| newSegments = this.reassignIndices(newSegments); |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added delete text action and its test.
The delete text action will be used by the BACKSPACE handler, which will delete a single char if a single place gets selected, and will delete a chunk of text if they are selected.
Currently, delete action has two modes:
Only #1 will be used currently since we don't have the handlers for mouse up/down, and selection service either.