Created
March 3, 2019 14:04
-
-
Save yurenju/6b57e90799bbbfe6309bce7fb4efd846 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
editor.addEventListener("input", ({ target, data, inputType }) => { | |
let start, end, text; | |
if (inputType === "insertText") { | |
start = { row: 0, column: target.selectionStart - 1 }; | |
end = { row: 0, column: 0 }; | |
text = data; | |
} else if (inputType === "deleteContentBackward") { | |
start = { row: 0, column: target.selectionStart }; | |
end = { row: 0, column: target.selectionStart + 1 }; | |
text = ""; | |
} | |
const ops = doc.setTextInRange(start, end, text); | |
const serialized = ops.map(serializeOperation); | |
const msg = new Messages.BufferProxy(); | |
msg.setOperationsList(serialized); | |
socket.emit("push-operations", msg.serializeBinary().buffer); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment