Better approach to creating new paragraph after new block type
This commit is contained in:
parent
669cfe3e8c
commit
095b70890e
@ -47,7 +47,6 @@ class MarkdownControl extends React.Component {
|
|||||||
this.renderMark = this.renderMark.bind(this);
|
this.renderMark = this.renderMark.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slate keeps track of selections, scroll position etc.
|
* Slate keeps track of selections, scroll position etc.
|
||||||
* So, onChange gets dispatched on every interaction (click, arrows, everything...)
|
* So, onChange gets dispatched on every interaction (click, arrows, everything...)
|
||||||
@ -58,7 +57,6 @@ class MarkdownControl extends React.Component {
|
|||||||
if (this.blockEdit) {
|
if (this.blockEdit) {
|
||||||
this.blockEdit = false;
|
this.blockEdit = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
this.setState({ state }, this.calculateMenuPositions);
|
this.setState({ state }, this.calculateMenuPositions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,6 +87,7 @@ class MarkdownControl extends React.Component {
|
|||||||
};
|
};
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,11 +191,23 @@ class MarkdownControl extends React.Component {
|
|||||||
|
|
||||||
state = state
|
state = state
|
||||||
.transform()
|
.transform()
|
||||||
.setBlock(type)
|
.insertBlock(type)
|
||||||
|
.apply();
|
||||||
|
|
||||||
|
this.setState({ state }, () => {
|
||||||
|
const blocks = this.state.state.document.getBlocks();
|
||||||
|
const last = blocks.last();
|
||||||
|
const normalized = state
|
||||||
|
.transform()
|
||||||
|
.focus()
|
||||||
|
.collapseToEndOf(last)
|
||||||
.splitBlock()
|
.splitBlock()
|
||||||
.setBlock(DEFAULT_NODE)
|
.setBlock(DEFAULT_NODE)
|
||||||
.apply();
|
.apply({
|
||||||
this.setState({ state }, this.calculateMenuPositions);
|
snapshot: false
|
||||||
|
});
|
||||||
|
this.setState({ state:normalized });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyDown(evt) {
|
handleKeyDown(evt) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user