fregante / GhostText

👻 Use your text editor to write in your browser. Everything you type in the editor will be instantly updated in the browser (and vice versa).
https://GhostText.fregante.com
MIT License
3.25k stars 116 forks source link

Put cursor at top of file, not bottom #258

Closed jidanni closed 1 year ago

jidanni commented 1 year ago

One notices in the editor (emacs) the cursor is always placed at the bottom of the file. This is in contrast with where we expect it: the top of the file.

fregante commented 1 year ago

What browser and editor are you using? Please read the text included in the issue templates, it asks to specify this information.

Cursor position and text selection should be brought over from the field, so if the cursor is at the top in the browser, it should be at the top in the editor too (on connection). Does that happen?

The only issue I know is that the selection isn't updated after the first connection:

jidanni commented 1 year ago

Chrome, emacs.

  1. We first click an edit link.
  2. Now we click your icon on the browser margin.
  3. Voila a buffer appears in emacs.

Well all through this process no cursor position has yet to be established in the browser.

In the emacs buffer the cursor is at the end of the buffer. We want it to be in the beginning of the buffer.

We try point-min in an emacs hook:

(if(/= 0 (user-uid))
    (progn
      (and (require 'atomic-chrome nil t)
       (add-hook 'atomic-chrome-edit-mode-hook
             (lambda ()
               (setq-local fill-column 99999)
               (goto-char (point-min))))
       (atomic-chrome-start-server))))

Alas that didn't help.

OK, starting over, and first clicking somewhere in the browser's textbox before clicking your icon... result: same problem.

Alas, the https://github.com/alpha22jp/atomic-chrome maintainer is not too active.

jidanni commented 1 year ago

Also checking interaction, the cursor also gets put at the bottom both ways on various interactions.

There is a reference to point-max here...

(defun atomic-chrome-send-buffer-text ()
  "Send request to update text with current buffer content."
  (interactive)
  (let ((socket (atomic-chrome-get-websocket (current-buffer)))
        (text (buffer-substring-no-properties (point-min) (point-max))))
    (when (and socket text)
      (websocket-send-text
       socket
       (json-encode
        (if (eq (websocket-server-conn socket) atomic-chrome-server-ghost-text)
            (list (cons "text" text))
          (list '("type" . "updateText")
                (cons "payload" (list (cons "text" text))))))))))
fregante commented 1 year ago

Cursor position and text selection should be brought over from the field

This is confirmed to happen in VS Code, so if it doesn't happen in your editor, you can open an issue in its GhostText plugin repo.

The browser extension correctly sets the cursor position where the user leaves it, even carrying over the initial selection, if any

https://user-images.githubusercontent.com/1402241/224995799-d1d8dede-f6a9-462b-a2cc-46c0052dbdb7.mov