mirror of
https://github.com/penpot/penpot.git
synced 2026-03-28 14:20:27 +01:00
Merge pull request #8726 from penpot/niwinz-main-bugfix-1
🐛 Fix null text crash on paste in text editor
This commit is contained in:
@@ -366,12 +366,19 @@ export function getInlineStyle(state, blockKey, offset) {
|
||||
const NEWLINE_REGEX = /\r\n?|\n/g;
|
||||
|
||||
function splitTextIntoTextBlocks(text) {
|
||||
if (text == null) {
|
||||
return [];
|
||||
}
|
||||
return text.split(NEWLINE_REGEX);
|
||||
}
|
||||
|
||||
export function insertText(state, text, attrs, inlineStyles) {
|
||||
const blocks = splitTextIntoTextBlocks(text);
|
||||
|
||||
if (blocks.length === 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const character = CharacterMetadata.create({style: OrderedSet(inlineStyles)});
|
||||
|
||||
let blockArray = DraftPasteProcessor.processText(
|
||||
|
||||
@@ -221,12 +221,13 @@
|
||||
|
||||
handle-pasted-text
|
||||
(fn [text _ _]
|
||||
(let [current-block-styles (ted/get-editor-current-block-data state)
|
||||
inline-styles (ted/get-editor-current-inline-styles state)
|
||||
style (merge current-block-styles inline-styles)
|
||||
state (-> (ted/insert-text state text style)
|
||||
(handle-change))]
|
||||
(st/emit! (dwt/update-editor-state shape state)))
|
||||
(when (seq text)
|
||||
(let [current-block-styles (ted/get-editor-current-block-data state)
|
||||
inline-styles (ted/get-editor-current-inline-styles state)
|
||||
style (merge current-block-styles inline-styles)
|
||||
state (-> (ted/insert-text state text style)
|
||||
(handle-change))]
|
||||
(st/emit! (dwt/update-editor-state shape state))))
|
||||
"handled")]
|
||||
|
||||
(mf/use-layout-effect on-mount)
|
||||
|
||||
Reference in New Issue
Block a user