Multi-line support and cursor position in overflow
Closed this issue ยท 7 comments
Hi all - this is a great project. Quick question:
- Is there support to insert new lines? This can be helpful when entering systems of equations
- When characters overflow and overflow is set to scroll the editor doesn't scroll to end itself. Hence the added characters and the caret position is hidden. Any thoughts on how to ensure the cursor is always in view?
To answer two, yes! Just set pointerevents to none in your css
Thanks @saivan for the answer. I had updated my second question. My question was:
- When characters overflow and overflow is set to scroll the editor doesn't scroll to end itself. Hence the added characters and the caret position is hidden. Any thoughts on how to ensure the cursor is always in view?
Any thoughts on it? Thanks!
You can do that reasonably easily too. Just get the position of the Cursor and when a key is pressed, set the scroll offset in JavaScript. You might want to make a pr for that because it sounds like useful functionality
Great will defn pr it once ready, @saivan . I can set the scroll offset for the element after a symbol/string is inserted. I was able to compile and run it. Looked through engine and guppy - any idea how i can get the current cursor position?
This is probably not a good way to go about it but up until now I had used
function getGuppyCursor() {
return (document.getElementsByClassName("cursor main_cursor")[0]
|| document.getElementsByClassName("mord main_cursor")[0])
}
You can then get the bbox of the cursor to find out where it is
Thanks for the insight @JMSS-Unknown and @saivan. Had some issues with build (local npm issue) so I ended up coming up with a solution using the existing guppy apis. This works really well. Note it uses jquery but can defn do it with vanilla js.
-
Add a event listener for change event name
Guppy("guppyTest").event("change", onEditorChange)
-
Implement event handler
function onEditorChange(){
document.getElementById("guppyTest").scrollLeft = 0; // reset scroll
var a = $(".main_cursor")[0]; // or use getGuppyCursor() from earlier comment
document.getElementById("guppy1").scrollLeft = $a.offset().left;
}
Closing for now since guppy instances can be used for multi-line support