File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,19 @@ describe('Selection', function () {
4141 } )
4242 } )
4343
44+ describe ( 'removeChars()' , function ( ) {
45+
46+ it ( 'removes multiple characters' , function ( ) {
47+ this . div = $ ( '<div>«Foo "bar" foo»</div>' ) [ 0 ]
48+ const range = rangy . createRange ( )
49+ range . selectNodeContents ( this . div )
50+ this . selection = new Selection ( this . div , range )
51+
52+ this . selection . removeChars ( [ '«' , '»' , '"' ] )
53+ expect ( this . div . innerHTML ) . toEqual ( 'Foo bar foo' )
54+ } )
55+ } )
56+
4457 describe ( 'textBefore() / textAfter()' , function ( ) {
4558
4659 beforeEach ( function ( ) {
Original file line number Diff line number Diff line change @@ -182,6 +182,14 @@ export default class Selection extends Cursor {
182182 this . setSelection ( )
183183 }
184184
185+ removeChars ( chars = [ ] ) {
186+ for ( let i = 0 ; i < chars . length ; i ++ ) {
187+ const char = chars [ i ]
188+ this . range = content . deleteCharacter ( this . host , this . range , char )
189+ }
190+ this . setSelection ( )
191+ }
192+
185193 toggleSurround ( startCharacter , endCharacter ) {
186194 if ( this . containsString ( startCharacter ) &&
187195 this . containsString ( endCharacter ) ) {
You can’t perform that action at this time.
0 commit comments