forked from ianstormtaylor/slate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add wrapTextAtRange tests, cleanup wrapText style and backwards handling
- Loading branch information
1 parent
17f703c
commit 90d4ece
Showing
33 changed files
with
395 additions
and
27 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
18 changes: 18 additions & 0 deletions
18
test/transforms/fixtures/wrap-text-at-range/across-blocks/index.js
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,18 @@ | ||
|
||
export default function (state) { | ||
const { document, selection } = state | ||
const texts = document.getTexts() | ||
const first = texts.first() | ||
const last = texts.last() | ||
const range = selection.merge({ | ||
anchorKey: first.key, | ||
anchorOffset: 2, | ||
focusKey: last.key, | ||
focusOffset: 2 | ||
}) | ||
|
||
return state | ||
.transform() | ||
.wrapTextAtRange(range, '[[', ']]') | ||
.apply() | ||
} |
12 changes: 12 additions & 0 deletions
12
test/transforms/fixtures/wrap-text-at-range/across-blocks/input.yaml
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,12 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: word | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: another |
12 changes: 12 additions & 0 deletions
12
test/transforms/fixtures/wrap-text-at-range/across-blocks/output.yaml
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,12 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: wo[[rd | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: an]]other |
18 changes: 18 additions & 0 deletions
18
test/transforms/fixtures/wrap-text-at-range/across-inlines/index.js
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,18 @@ | ||
|
||
export default function (state) { | ||
const { document, selection } = state | ||
const texts = document.getTexts() | ||
const first = texts.first() | ||
const last = texts.last() | ||
const range = selection.merge({ | ||
anchorKey: first.key, | ||
anchorOffset: 2, | ||
focusKey: last.key, | ||
focusOffset: 2 | ||
}) | ||
|
||
return state | ||
.transform() | ||
.wrapTextAtRange(range, '[[', ']]') | ||
.apply() | ||
} |
15 changes: 15 additions & 0 deletions
15
test/transforms/fixtures/wrap-text-at-range/across-inlines/input.yaml
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,15 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: inline | ||
type: link | ||
nodes: | ||
- kind: text | ||
text: word | ||
- kind: inline | ||
type: link | ||
nodes: | ||
- kind: text | ||
text: another |
15 changes: 15 additions & 0 deletions
15
test/transforms/fixtures/wrap-text-at-range/across-inlines/output.yaml
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,15 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: inline | ||
type: link | ||
nodes: | ||
- kind: text | ||
text: wo[[rd | ||
- kind: inline | ||
type: link | ||
nodes: | ||
- kind: text | ||
text: an]]other |
18 changes: 18 additions & 0 deletions
18
test/transforms/fixtures/wrap-text-at-range/backwards-selection/index.js
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,18 @@ | ||
|
||
export default function (state) { | ||
const { document, selection } = state | ||
const texts = document.getTexts() | ||
const first = texts.first() | ||
const range = selection.merge({ | ||
anchorKey: first.key, | ||
anchorOffset: 3, | ||
focusKey: first.key, | ||
focusOffset: 1, | ||
isBackward: true | ||
}) | ||
|
||
return state | ||
.transform() | ||
.wrapTextAtRange(range, '[[', ']]') | ||
.apply() | ||
} |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/backwards-selection/input.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: word |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/backwards-selection/output.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: w[[or]]d |
17 changes: 17 additions & 0 deletions
17
test/transforms/fixtures/wrap-text-at-range/empty-block/index.js
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,17 @@ | ||
|
||
export default function (state) { | ||
const { document, selection } = state | ||
const texts = document.getTexts() | ||
const first = texts.first() | ||
const range = selection.merge({ | ||
anchorKey: first.key, | ||
anchorOffset: 0, | ||
focusKey: first.key, | ||
focusOffset: 0 | ||
}) | ||
|
||
return state | ||
.transform() | ||
.wrapTextAtRange(range, '[[', ']]') | ||
.apply() | ||
} |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/empty-block/input.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: "" |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/empty-block/output.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: "[[]]" |
17 changes: 17 additions & 0 deletions
17
test/transforms/fixtures/wrap-text-at-range/end-of-block/index.js
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,17 @@ | ||
|
||
export default function (state) { | ||
const { document, selection } = state | ||
const texts = document.getTexts() | ||
const first = texts.first() | ||
const range = selection.merge({ | ||
anchorKey: first.key, | ||
anchorOffset: 2, | ||
focusKey: first.key, | ||
focusOffset: 4 | ||
}) | ||
|
||
return state | ||
.transform() | ||
.wrapTextAtRange(range, '[[', ']]') | ||
.apply() | ||
} |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/end-of-block/input.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: word |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/end-of-block/output.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: wo[[rd]] |
17 changes: 17 additions & 0 deletions
17
test/transforms/fixtures/wrap-text-at-range/middle-of-block/index.js
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,17 @@ | ||
|
||
export default function (state) { | ||
const { document, selection } = state | ||
const texts = document.getTexts() | ||
const first = texts.first() | ||
const range = selection.merge({ | ||
anchorKey: first.key, | ||
anchorOffset: 1, | ||
focusKey: first.key, | ||
focusOffset: 3 | ||
}) | ||
|
||
return state | ||
.transform() | ||
.wrapTextAtRange(range, '[[', ']]') | ||
.apply() | ||
} |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/middle-of-block/input.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: word |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/middle-of-block/output.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: w[[or]]d |
17 changes: 17 additions & 0 deletions
17
test/transforms/fixtures/wrap-text-at-range/start-of-block/index.js
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,17 @@ | ||
|
||
export default function (state) { | ||
const { document, selection } = state | ||
const texts = document.getTexts() | ||
const first = texts.first() | ||
const range = selection.merge({ | ||
anchorKey: first.key, | ||
anchorOffset: 0, | ||
focusKey: first.key, | ||
focusOffset: 2 | ||
}) | ||
|
||
return state | ||
.transform() | ||
.wrapTextAtRange(range, '[[', ']]') | ||
.apply() | ||
} |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/start-of-block/input.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: word |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/start-of-block/output.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: "[[wo]]rd" |
17 changes: 17 additions & 0 deletions
17
test/transforms/fixtures/wrap-text-at-range/whole-block/index.js
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,17 @@ | ||
|
||
export default function (state) { | ||
const { document, selection } = state | ||
const texts = document.getTexts() | ||
const first = texts.first() | ||
const range = selection.merge({ | ||
anchorKey: first.key, | ||
anchorOffset: 0, | ||
focusKey: first.key, | ||
focusOffset: 4 | ||
}) | ||
|
||
return state | ||
.transform() | ||
.wrapTextAtRange(range, '[[', ']]') | ||
.apply() | ||
} |
7 changes: 7 additions & 0 deletions
7
test/transforms/fixtures/wrap-text-at-range/whole-block/input.yaml
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,7 @@ | ||
|
||
nodes: | ||
- kind: block | ||
type: paragraph | ||
nodes: | ||
- kind: text | ||
text: word |
Oops, something went wrong.