1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 09:04:31 +02:00

Focus and blur should not clear marks on selection (#338)

* Do not clear mark on focus/blur

* Add tests
This commit is contained in:
Nicolas Gaborit
2016-09-21 20:43:03 +02:00
committed by Ian Storm Taylor
parent 27168a388d
commit bcb2fc39e5
5 changed files with 98 additions and 3 deletions

View File

@@ -371,9 +371,18 @@ export function setSelectionOperation(transform, properties) {
prevProps[k] = selection[k]
}
// If the current selection has marks, and the new selection doesn't change
// them in some way, they are old and should be removed.
if (selection.marks && properties.marks == selection.marks) {
// If the selection moves, clear any marks, unless the new selection
// does change the marks in some way
const moved = [
'anchorKey',
'anchorOffset',
'focusKey',
'focusOffset',
].some(p => props.hasOwnProperty(p))
if (selection.marks
&& properties.marks == selection.marks
&& moved) {
props.marks = null
}

View File

@@ -0,0 +1,26 @@
import assert from 'assert'
import { Mark } from '../../../../../..'
export default function (state) {
const { startText, selection } = state
const sel = selection.merge({
marks: Mark.createSet([
Mark.create({
type: 'bold'
})
])
})
const next = state
.transform()
.addMark('bold')
.focus()
.blur()
.apply()
assert.deepEqual(
next.selection.toJS(),
sel.toJS()
)
}

View File

@@ -0,0 +1,17 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one
- kind: block
type: paragraph
nodes:
- kind: text
text: two
- kind: block
type: paragraph
nodes:
- kind: text
text: three

View File

@@ -0,0 +1,26 @@
import assert from 'assert'
import { Mark } from '../../../../../..'
export default function (state) {
const { startText, selection } = state
const sel = selection.merge({
isFocused: true,
marks: Mark.createSet([
Mark.create({
type: 'bold'
})
])
})
const next = state
.transform()
.addMark('bold')
.focus()
.apply()
assert.deepEqual(
next.selection.toJS(),
sel.toJS()
)
}

View File

@@ -0,0 +1,17 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one
- kind: block
type: paragraph
nodes:
- kind: text
text: two
- kind: block
type: paragraph
nodes:
- kind: text
text: three