Weird crash when trying to create new line after deleting line
acgollapalli opened this issue · 8 comments
How to replicate:
Start with something like this:
(defn hello
[]
(println "hello world!"))
Put cursor on last line, and ensure you are in normal-mode.
In rapid succession type the following characters. "d, d, i, enter".
The editor crashes.
Great. Thank you! For the replicate to work, there should be a 4th line, which is empty and the cursor should be on line 3: "hello world!"
Reproducing with --jframe flag will reveal this stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException
at clojure.lang.RT.subvec(RT.java:1616)
at clojure.core$subvec.invokeStatic(core.clj:3829)
at clojure.core$subvec.invoke(core.clj:3818)
at liq.buffer$insert_in_vector.invokeStatic(buffer.cljc:48)
at liq.buffer$insert_in_vector.invoke(buffer.cljc:39)
at liq.buffer$insert_char$fn__866.invoke(buffer.cljc:565)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.core$update_in$up__6853.invoke(core.clj:6185)
at clojure.core$update_in$up__6853.invoke(core.clj:6184)
at clojure.core$update_in.invokeStatic(core.clj:6186)
at clojure.core$update_in.doInvoke(core.clj:6172)
at clojure.lang.RestFn.invoke(RestFn.java:445)
at liq.buffer$insert_char.invokeStatic(buffer.cljc:565)
at liq.buffer$insert_char.invoke(buffer.cljc:561)
at liq.buffer$insert_char.invokeStatic(buffer.cljc:568)
at liq.buffer$insert_char.invoke(buffer.cljc:561)
at liq.editor$handle_input$fn__1194.invoke(editor.cljc:360)
Evaluating this piece of code will also reproduce (but without crashing liquid):
(ns user
(:require [liq.buffer :refer :all]))
(-> (buffer "aa\nbb\n")
down
delete-line
set-insert-mode
(insert-char "\n"))
These two lines should yield the same result:
(str
(with-out-str (clojure.pprint/pprint ((-> (buffer "aa\nbb\n") down delete-line set-insert-mode) :liq.buffer/cursor)))
(with-out-str (clojure.pprint/pprint ((-> (buffer "aa\n") down set-insert-mode) :liq.buffer/cursor))))
; OUTPUT:
; #:liq.buffer{:row 2, :col 0}
; #:liq.buffer{:row 2, :col 1}
They do not. I have created a test and fixed the error and commitet.
(Thank you @acgollapalli . I have seen the error occasionally, but without being able to observe what exactly had happened.)
Thank you! The change fixed the issue for me.
Great @acgollapalli . Nice catch. I will be looking forward for the pull request :-)
#52 has been added. Thanks!
Fixed long ago.