Skip to content

Commit

Permalink
FIX for marked text, broken in PR #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Worrall committed Oct 6, 2023
1 parent 9784c60 commit 3e733c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 1 addition & 5 deletions Lexical/Core/Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ func checkIfTokenOrCanTextBeInserted(node: TextNode) -> Bool {

// triggered by selection change event from the UITextView
internal func onSelectionChange(editor: Editor) {
if editor.isUpdating {
// If for example a Lexical plugin requests the text view to become first responder (i.e.
// after some kind of UI was presented), we don't want to overwrite the Lexical selection here.
return
}
// Note: we have to detect selection changes here even if an update is in progress, otherwise marked text breaks!
do {
try editor.updateWithCustomBehaviour(mode: UpdateBehaviourModificationMode(suppressReconcilingSelection: true, suppressSanityCheck: true)) {
let nativeSelection = editor.getNativeSelection()
Expand Down
7 changes: 6 additions & 1 deletion Plugins/LexicalLinkPlugin/LexicalLinkPlugin/LinkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,20 @@ open class LinkPlugin: Plugin {

func insertLink(linkPayload: LinkPayload?, editor: Editor) {
do {
var modifiedSelection: BaseSelection?
try editor.update {
getActiveEditorState()?.selection = linkPayload?.originalSelection
try toggleLink(url: linkPayload?.urlString)
modifiedSelection = try getSelection()?.clone()
}
lexicalView?.textViewBecomeFirstResponder()
try editor.update {
getActiveEditorState()?.selection = modifiedSelection
}
} catch {
print("\(error)")
}

lexicalView?.textViewBecomeFirstResponder()
}

func toggleLink(url: String?) throws {
Expand Down

0 comments on commit 3e733c7

Please sign in to comment.