micro icon indicating copy to clipboard operation
micro copied to clipboard

Option to turn off cursor wrapping

Open pachpict opened this issue 1 year ago • 5 comments

Suggested feature

An option ('cursorwrapping'), when false, stops the cursor moving to the next or previous line when it reaches the end of a line. Defaults to true. Therefore when set to false the editor acts much like a typewriter.

Context

Micro is proving an invaluable tool for creating spacial Braille applications for the Canute hardware. A lot of these applications* are using the micro editor within fixed width files with the ideal use-case being the user is able to pan all the way to the far left or right without leaving that line. It is much harder to tell a line is changing on a multiline Braille display because it takes up to nine seconds to refresh.


  • Applications that would benefit from this include Braille-to-tactile-super-large-print, free drawing (a canvas, essentially), flow diagrams.

pachpict avatar Oct 16 '23 17:10 pachpict

As a user with some relatively minor disabilities, I am always amazed when I read about people with blindness using a PC. I think that's just amazing. What talent, what skill, such endurance. You all have my utmost respect.

I support this feature request. The default you have suggested means that nobody will even notice it, unless they deliberately turn it on to help them.

I thought of an implementation detail here which might be important, so I hope sharing this thought is useful to you:

When you are considering the cursor wrapping to the next line, when it reaches the end of the line, do you mean the end of the line, in the file, or the end of the line, on screen? I'm thinking about long lines that have been 'wrapped', where one real line in the file, becomes multiple lines on screen. Would you want it to not 'cursor-wrap' when it reaches the end of the screen, or the actual end of the line (ie, where the \n is)?

I have no idea if visually impaired users prefer line wrapping to even be enabled! I would guess that exceedingly long lines are even more annoying in braille, so you would probably use line-wrapping, so if you're considering not wrapping the cursor, at the end of a line, this would be an important distinction.

Hope this helps!

pallaswept avatar Oct 17 '23 19:10 pallaswept

This can be already done using Lua. You can try adding this to init.lua:

local util = import("micro/util")

function preCursorLeft(bp)
    return bp.Cursor.X > 0
end

function preCursorRight(bp)
    return bp.Cursor.X < util.CharacterCountInString(bp.Buf:Line(bp.Cursor.Y))
end

It will prevent Left and Right keys from moving the cursor to the next or previous line.

Admittedly, this solution is probably not quite complete, at least for the following reasons:

  • It only covers simple cursor movements, but we should probably also take into account text selection (Shift-Left and Shift-Right), as well as cursor movements by a word (Ctrl-Left and Ctrl-Right) and so on.
  • It assumes that the line is a "logical" line in the file, and as @pallaswept already pointed out, it may be a long wrapped line which spans multiple visual lines on the screen (if the softwrap option is turned on), so the cursor may be actually at the left or right edge of the screen (i.e. at the beginning or end of a visual line), yet not at the beginning or end of the logical line, and the above solution does not prevent the cursor from moving to the next or previous visual line in this case.

Nevertheless, you can already try out this simple limited solution, to test how well this feature works in practice (since it doesn't even require you to recompile micro, just add a few lines to init.lua).

dmaluka avatar Oct 21 '23 17:10 dmaluka

Thanks both.

Re @pallaswept Q: I think it should be restricted to not cursor wrapping actual line breaks in the file. All the applications I am working on that would benefit from this functionality already either have softwrap turned off or they restrict line length (to under 40, the traditional max for a Braille line). I can't immediately see a use-case for stopping the cursor soft line wrapping.

Re @dmaluka suggestion: Thank you, that's great. Is there a way of turning that functionality off and on as an argument passed to the micro command? Excuse my ignorance on this; I've used micro a lot but never got into that side of it.

pachpict avatar Oct 23 '23 18:10 pachpict

I was going to say "yes", but I've found that micro currently supports turning options on/off via command line (micro -option) for its built-in options only, not for options provided by lua plugins.

...Generally the easiest (and pretty elegant) way to make this functionality switchable on/off is to simply move this Lua code from init.lua to a separate plugin. After that you will be able to turn it on/off just by turning the plugin itself on/off.

Precise how to:

  1. create ~/.config/micro/plug/cursorwrap directory
  2. create cursorwrap.lua file in this directory
  3. add the above Lua code to this file

After that, cursorwrap will be enabled by default, and you will be able to disable it via set cursorwrap off command in micro, or by manually adding "cursorwrap": false to settings.json. But as I said, unfortunately you will not be able to do it via micro -cursorwrap=off when starting micro, since micro currently doesn't support it.

Maybe it's not hard to fix. I'll try to do it soon, if I have time.

dmaluka avatar Oct 24 '23 01:10 dmaluka

FYI: https://github.com/zyedidia/micro/issues/2373#issuecomment-1837300855

dmaluka avatar Dec 03 '23 01:12 dmaluka