Skip to content

Instantly share code, notes, and snippets.

@yurenju
Created March 3, 2019 14:04
Show Gist options
  • Save yurenju/6b57e90799bbbfe6309bce7fb4efd846 to your computer and use it in GitHub Desktop.
Save yurenju/6b57e90799bbbfe6309bce7fb4efd846 to your computer and use it in GitHub Desktop.
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