airstruck / luigi

Lovely User Interfaces for Game Inventors
MIT License
113 stars 23 forks source link

Allow user to move caret to end of a line or its beginning #26

Closed rm-code closed 8 years ago

rm-code commented 8 years ago

On Windows the user can press the 'home' or 'end' key to jump around. On OSX he has to use cmd+arrow keys to move around.

If the user holds down shift while performing the above operations the whole line will be selected from where the caret was currently placed.

jump

airstruck commented 8 years ago

Very nice.

airstruck commented 8 years ago

@rm-code, quick question. On most non-Mac systems I've seen, ctrl-left and ctrl-right move the caret one word at a time, and ctrl-shift-left and ctrl-shift-left move the end of the selection range one word at a time (see bottom of #23). What's the usual key combo for this on Mac?

rm-code commented 8 years ago

On OSX you'd usually use the alt- (also know as "option"-) key to move one word at a time. Same goes for moving the selection (alt-shift-left / right).

I've actually been working on this, but it didn't turn out as good as I wanted it to be :grin:

Basically tried it like this:

local function jumpWordLeft (self, alterRange)
    trimRange(self)
    local text, endIndex = self.value:reverse(), self.endIndex
    local pos = text:find('%s', #text - endIndex + 1)
    if pos then
        selectRange(self, not alterRange and #text - pos, #text - pos)
    end
end

I guess looking for non-whitespace chars would've made more sense ^^

airstruck commented 8 years ago

I also couldn't decide whether to break words only on whitespace, or on any non-alphanumeric character. I've seen both behaviors and I'm not sure which I prefer. I guess either behavior is better than nothing, though. I'll take a closer look at your solution when I get a chance :)