mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-28 09:29:49 +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:
committed by
Ian Storm Taylor
parent
27168a388d
commit
bcb2fc39e5
@@ -371,9 +371,18 @@ export function setSelectionOperation(transform, properties) {
|
|||||||
prevProps[k] = selection[k]
|
prevProps[k] = selection[k]
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the current selection has marks, and the new selection doesn't change
|
// If the selection moves, clear any marks, unless the new selection
|
||||||
// them in some way, they are old and should be removed.
|
// does change the marks in some way
|
||||||
if (selection.marks && properties.marks == selection.marks) {
|
const moved = [
|
||||||
|
'anchorKey',
|
||||||
|
'anchorOffset',
|
||||||
|
'focusKey',
|
||||||
|
'focusOffset',
|
||||||
|
].some(p => props.hasOwnProperty(p))
|
||||||
|
|
||||||
|
if (selection.marks
|
||||||
|
&& properties.marks == selection.marks
|
||||||
|
&& moved) {
|
||||||
props.marks = null
|
props.marks = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
test/transforms/fixtures/on-selection/blur/marks/index.js
Normal file
26
test/transforms/fixtures/on-selection/blur/marks/index.js
Normal 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()
|
||||||
|
)
|
||||||
|
}
|
17
test/transforms/fixtures/on-selection/blur/marks/input.yaml
Normal file
17
test/transforms/fixtures/on-selection/blur/marks/input.yaml
Normal 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
|
26
test/transforms/fixtures/on-selection/focus/marks/index.js
Normal file
26
test/transforms/fixtures/on-selection/focus/marks/index.js
Normal 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()
|
||||||
|
)
|
||||||
|
}
|
17
test/transforms/fixtures/on-selection/focus/marks/input.yaml
Normal file
17
test/transforms/fixtures/on-selection/focus/marks/input.yaml
Normal 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
|
Reference in New Issue
Block a user