I have (setq scroll-margin 10) and if I single click an item in the tree inside this margin (either 10 lines in from the top or bottom) the tree scrolls to make the selected item more than 10 lines away from the top or bottom margins (fine) but also opens the file as if I have double clicked or hit RET.
The scroll behaviour is fine and perhaps expected but I see no reason why the file should also open.
I can confirm this is happening and the cause is treemacs' mouse dragging support. It looks like emacs thinks the mouse click in combination with a margin-forced scroll means you have dragged the mouse and thus calls treemacs-dragleftclick-action.
I don't think this is something that can be reasonably worked around, so there's 2 things you can do here:
(fset #'treemacs-dragleftclick-action #'ignore)Thanks @Alexander-Miller. Do you know how I would set scroll-margin just for Treemacs?
You can do it in a mode hook like this:
(add-hook 'treemacs-mode-hook
(defun set-local-scroll-margin ()
(setq-local scroll-margin 0)))