1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 19:01:54 +02:00

fix setMarkByKey by adding tests, closes #319

This commit is contained in:
Ian Storm Taylor
2016-09-14 15:04:38 -07:00
parent b7f317ac4b
commit 7756f769ec
5 changed files with 50 additions and 4 deletions

View File

@@ -287,14 +287,14 @@ class Text extends new Record(DEFAULTS) {
*/
updateMark(index, length, mark, properties) {
const m = mark.merge(properties)
const characters = this.characters.map((char, i) => {
if (i < index) return char
if (i >= index + length) return char
let { marks } = char
const j = marks.indexOf(mark)
let m = marks.get(j)
m = m.merge(properties)
marks = marks.set(j, m)
if (!marks.has(mark)) return char
marks = marks.remove(mark)
marks = marks.add(m)
char = char.merge({ marks })
return char
})

View File

@@ -245,6 +245,7 @@ function setMark(state, operation) {
let { document } = state
let node = document.assertPath(path)
node = node.updateMark(offset, length, mark, properties)
debugger
document = document.updateDescendant(node)
state = state.merge({ document })
return state

View File

@@ -0,0 +1,21 @@
export default function (state) {
const { document, selection } = state
const first = document.getTexts().first()
return state
.transform()
.setMarkByKey(
first.key,
0,
first.length,
{
type: 'bold',
data: { key: true }
},
{
data: { key: false }
}
)
.apply()
}

View File

@@ -0,0 +1,12 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word
marks:
- type: bold
data:
key: true

View File

@@ -0,0 +1,12 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word
marks:
- type: bold
data:
key: false