Skip to content

Commit b1097af

Browse files
authored
Merge pull request #215 from wordpress-mobile/issue/211-inline-format-selection
Issue/211 inline format selection
2 parents 76d623e + 27d14ea commit b1097af

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,7 @@ class InlineFormatter(editor: AztecText, codeStyle: CodeStyle) : AztecFormatter(
407407
}
408408
}
409409

410-
val selectedText = editableText.subSequence(start, end).toString().replace("\n", "")
411-
val styledText = builder.toString()
412-
413-
return !styledText.isEmpty() && selectedText.contains(styledText)
410+
return editableText.subSequence(start, end).toString() == builder.toString()
414411
}
415412
}
416413
}

aztec/src/test/kotlin/org/wordpress/aztec/AztecToolbarTest.kt

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class AztecToolbarTest {
288288
}
289289

290290
/**
291-
* Test toggle state of formatting button as we move selection to differently styled text
291+
* Test toggle state of formatting button as selection moves to differently styled text.
292292
*
293293
* @throws Exception
294294
*/
@@ -312,7 +312,7 @@ class AztecToolbarTest {
312312
//bold and bold/italic styles selected
313313
editText.setSelection(2, 7)
314314
Assert.assertTrue(boldButton.isChecked)
315-
Assert.assertTrue(italicButton.isChecked)
315+
Assert.assertFalse(italicButton.isChecked)
316316
Assert.assertFalse(strikeThroughButton.isChecked)
317317

318318
//cursor is at italic text
@@ -335,64 +335,67 @@ class AztecToolbarTest {
335335

336336
//whole text selected
337337
editText.setSelection(0, editText.length() - 1)
338-
Assert.assertTrue(boldButton.isChecked)
339-
Assert.assertTrue(italicButton.isChecked)
340-
Assert.assertTrue(strikeThroughButton.isChecked)
338+
Assert.assertFalse(boldButton.isChecked)
339+
Assert.assertFalse(italicButton.isChecked)
340+
Assert.assertFalse(strikeThroughButton.isChecked)
341341
}
342342

343343
/**
344-
* Select whole text with one common style applied to it and another style applied to part of it
345-
* ("di" from <b>bold</b><b><i>italic</i></b>) and extend partially applied style (italic) to other part of selection
344+
* Select part of text with one common style (bold) applied to it and another style (italic)
345+
* applied to part of it ("di" from <b>bold</b><b><i>italic</i></b>) and extend partially
346+
* applied style (italic) to other part of selection.
346347
*
347348
* @throws Exception
348349
*/
349350
@Test
350351
@Throws(Exception::class)
351-
fun removeStyleItalicPartialSelection() {
352+
fun extendStyleItalicPartialSelection() {
352353
editText.fromHtml("<b>bold</b><b><i>italic</i></b>")
353354

354355
val selectedText = editText.text.substring(3, 5)
355356
Assert.assertEquals("di", selectedText) //sanity check
356357

357358
editText.setSelection(3, 5)
358359
Assert.assertTrue(boldButton.isChecked)
359-
Assert.assertTrue(italicButton.isChecked)
360+
Assert.assertFalse(italicButton.isChecked)
360361

361362
italicButton.performClick()
362-
Assert.assertEquals("<b>boldi</b><b><i>talic</i></b>", editText.toHtml())
363+
Assert.assertEquals("<b>bol</b><b><i>ditalic</i></b>", editText.toHtml())
363364
}
364365

365366
/**
366-
* Select whole text with one common style applied to it and another style applied to part of it
367-
* ("ds" from <b>bold</b><b><del>strike</del></b>) and extend partially applied style (strikethrough) to other part of selection
367+
* Select part of text with one common style applied to it (bold) and another style (strikethrough)
368+
* applied to part of it ("ds" from <b>bold</b><b><del>strike</del></b>) and extend partially
369+
* applied style (strikethrough) to other part of selection.
368370
*
369371
* @throws Exception
370372
*/
371373
@Test
372374
@Throws(Exception::class)
373-
fun removeStyleStrikethroughPartialSelection() {
375+
fun extendStyleStrikethroughPartialSelection() {
374376
editText.fromHtml("<b>bold</b><b><del>strike</del></b>")
375377

376378
val selectedText = editText.text.substring(3, 5)
377379
Assert.assertEquals("ds", selectedText) //sanity check
378380

379381
editText.setSelection(3, 5)
380382
Assert.assertTrue(boldButton.isChecked)
381-
Assert.assertTrue(strikeThroughButton.isChecked)
383+
Assert.assertFalse(strikeThroughButton.isChecked)
382384

383385
strikeThroughButton.performClick()
384-
Assert.assertEquals("<b>bolds</b><b><del>trike</del></b>", editText.toHtml())
386+
Assert.assertEquals("<b>bol</b><b><del>dstrike</del></b>", editText.toHtml())
385387
}
386388

387389
/**
388-
* Select part of text with one common style applied to it and other style applied to part of it
389-
* ("italic" from <b>bold</b><b><i>italic</i></b>) and remove partially applied style (italic) form it
390+
* Select part of text with one common style applied (bold) to it and other style (italic)
391+
* applied to part of it ("italic" from <b>bold</b><b><i>italic</i></b>) and extend partially
392+
* applied style (italic) to other part of selection.
390393
*
391394
* @throws Exception
392395
*/
393396
@Test
394397
@Throws(Exception::class)
395-
fun removeStyleFromPartialSelection() {
398+
fun extendStyleFromPartialSelection() {
396399
editText.fromHtml("<b>bold</b><b><i>italic</i></b>")
397400

398401
val selectedText = editText.text.substring(4, editText.length())
@@ -406,24 +409,24 @@ class AztecToolbarTest {
406409
}
407410

408411
/**
409-
* Select whole text with one common style applied to it and another style applied to part of it
410-
* extend partial style (italic) to whole selection
412+
* Select whole text with one common style (bold) applied to it and another style (italic)
413+
* applied to part of it and extend partial style (italic) to whole selection.
411414
*
412415
* @throws Exception
413416
*/
414417
@Test
415418
@Throws(Exception::class)
416-
fun removeStyleFromWholeSelection() {
419+
fun extendStyleFromWholeSelection() {
417420
editText.fromHtml("<b>bold</b><b><i>italic</i></b>")
418421

419422
editText.setSelection(0, editText.length())
420423

421424
italicButton.performClick()
422-
Assert.assertEquals("<b>bolditalic</b>", editText.toHtml())
425+
Assert.assertEquals("<b><i>bolditalic</i></b>", editText.toHtml())
423426
}
424427

425428
/**
426-
* Select whole text inside editor and remove styles from it while maintaining selection.
429+
* Select whole text inside editor and remove/add styles while maintaining selection.
427430
*
428431
* @throws Exception
429432
*/
@@ -438,13 +441,13 @@ class AztecToolbarTest {
438441
Assert.assertEquals("bold<i>italic</i>", editText.toHtml())
439442

440443
italicButton.performClick()
441-
Assert.assertEquals("bolditalic", editText.toHtml())
444+
Assert.assertEquals("<i>bolditalic</i>", editText.toHtml())
442445

443446
italicButton.performClick()
444-
Assert.assertEquals("<i>bolditalic</i>", editText.toHtml())
447+
Assert.assertEquals("bolditalic", editText.toHtml())
445448

446449
boldButton.performClick()
447-
Assert.assertEquals("<i><b>bolditalic</b></i>", editText.toHtml())
450+
Assert.assertEquals("<b>bolditalic</b>", editText.toHtml())
448451
}
449452

450453
/**
@@ -492,7 +495,7 @@ class AztecToolbarTest {
492495
}
493496

494497
/**
495-
* Test styling inside HiddenHtmlSpan
498+
* Test styling inside HiddenHtmlSpan.
496499
*
497500
* @throws Exception
498501
*/
@@ -520,7 +523,7 @@ class AztecToolbarTest {
520523
}
521524

522525
/**
523-
* Test the correctness of span-to-HTML conversion after deleting a span from the editor
526+
* Test the correctness of span-to-HTML conversion after deleting a span from the editor.
524527
*
525528
* @throws Exception
526529
*/

0 commit comments

Comments
 (0)