-
Notifications
You must be signed in to change notification settings - Fork 1
Add delete text action #15
base: master
Are you sure you want to change the base?
Conversation
| 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) | ||
| ]; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // to remove the single char at the cursor |
| let startIndex = startSegment.index; | ||
| let endIndex = endSegment.index; | ||
| if (startSegment.content.length === 0) { | ||
| startIndex = startIndex - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| startIndex = startIndex - 1; | |
| startIndex--; |
| startIndex = startIndex - 1; | ||
| } | ||
| if (endSegment.content.length === 0) { | ||
| endIndex = endIndex + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| endIndex = endIndex + 1; | |
| endIndex++; |
|
|
||
| if (endIndex - startIndex - 1 > 0) { | ||
| newSegments = remove<ISegment>(newSegments, startIndex + 1, endIndex - startIndex - 1); | ||
| newSegments = this.rematchIndex(newSegments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| newSegments = this.rematchIndex(newSegments); | |
| newSegments = this.reassignIndices(newSegments); |
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.