Enter character for edit_line? #860

Open
KCErb opened this Issue Aug 19, 2014 · 10 comments

Comments

Projects
None yet
5 participants
@KCErb
Member

KCErb commented Aug 19, 2014

Hi all, as noted in the mailing list edit_line is behaving incorrectly when it receives the enter character.

The Problem
I would expect edit_line to give me back all of the characters typed into it with the text method. But pressing enter (\n) doesn't trigger the modify listener. So it doesn't get added to the text.

In Shoes 3 pressing enter selects the text. In Shoes 4 enter does nothing.

What do we want 4 to do? The same as 3? (I know that's the default answer but in this case it seems counterintuitive to me.)

My thoughts
My preference would be to allow special characters like tab and enter in edit_line. The reasoning is that single-row edit_lines are often used for typing a quick command / search and expecting a block to fire on enter. It's easy to set up the block with something like this:

Shoes.app do
  edit_line do |e|
    do_stuff if e.text[-1] == "\n"
    e.text = e.text.chop
  end
end

Another option I'd be in favor of would be creating a special enter: proc much like how click works.

But that's 4.1+ stuff, and for this issue I'm mainly interested in not having enter do nothing on edit lines.

My Solution
Simply changing SINGLE to MULTI right here does exactly what I want. Since wrap isn't set, the box remains one line even for long text.

Since MULTI allows tab and enter characters, the user can control what happens on tab and enter. Instead of the next item getting tabbed to, the user can select which item should gain focus after a tab.
(That is, if focus worked #610)

@jasonrclark

This comment has been minimized.

Show comment
Hide comment
@jasonrclark

jasonrclark Aug 19, 2014

Member

Hmm, trying that out locally changing that to MULTI allows multiple lines, and I thought the main (only?) real difference between edit_line and edit_box was that edit_line is always single line...

Definitely would like to get an event of some sort fired for this if possible, since I completely agree with the use-case of hitting Enter on a search box, but it might need to get handled specially in some way.

Member

jasonrclark commented Aug 19, 2014

Hmm, trying that out locally changing that to MULTI allows multiple lines, and I thought the main (only?) real difference between edit_line and edit_box was that edit_line is always single line...

Definitely would like to get an event of some sort fired for this if possible, since I completely agree with the use-case of hitting Enter on a search box, but it might need to get handled specially in some way.

@KCErb

This comment has been minimized.

Show comment
Hide comment
@KCErb

KCErb Aug 19, 2014

Member

I agree that the purpose is for it to be single line, but if you play around in 3 it's pretty easy to get multiple lines either by copying and pasting text with enter characters in it. Or by just typing long lines of text since the Shoes 3 edit_line wraps when too much text is entered in.

The behavior I'd expect is something like the google search bar. Playing around with it over at google.com, I think it just removes the \n character from strings that are handed to it.

Maybe the answer is using MULTI and no WRAP and something that cleans new line characters out of the string before displaying.

How does that sound? 😄

Member

KCErb commented Aug 19, 2014

I agree that the purpose is for it to be single line, but if you play around in 3 it's pretty easy to get multiple lines either by copying and pasting text with enter characters in it. Or by just typing long lines of text since the Shoes 3 edit_line wraps when too much text is entered in.

The behavior I'd expect is something like the google search bar. Playing around with it over at google.com, I think it just removes the \n character from strings that are handed to it.

Maybe the answer is using MULTI and no WRAP and something that cleans new line characters out of the string before displaying.

How does that sound? 😄

@jasonrclark

This comment has been minimized.

Show comment
Hide comment
@jasonrclark

jasonrclark Aug 19, 2014

Member

Definitely a possibility.

I do wonder if we get any events on the keypress at the lower levels in SWT that we could hook more directly to handle it, and avoid having to change the settings on the SWT element at all. Haven't been in the keypress code for a while, but it would be worth looking more closely at exactly what events are fired there since it might yield an easier way to get where we want to go.

Member

jasonrclark commented Aug 19, 2014

Definitely a possibility.

I do wonder if we get any events on the keypress at the lower levels in SWT that we could hook more directly to handle it, and avoid having to change the settings on the SWT element at all. Haven't been in the keypress code for a while, but it would be worth looking more closely at exactly what events are fired there since it might yield an easier way to get where we want to go.

@ccoupe

This comment has been minimized.

Show comment
Hide comment
@ccoupe

ccoupe Aug 19, 2014

I'd like to fix the Shoes 3.2 behavour as well. I'll look into the options for GTK and Cocoa... Doable. It looks to me like an enter: proc would be the best for compatibility.

ccoupe commented Aug 19, 2014

I'd like to fix the Shoes 3.2 behavour as well. I'll look into the options for GTK and Cocoa... Doable. It looks to me like an enter: proc would be the best for compatibility.

@ccoupe

This comment has been minimized.

Show comment
Hide comment
@ccoupe

ccoupe Aug 20, 2014

I'd like to suggest a different name instead of enter: That might be confusing to someone learning Shoes since it's not entering, it's exiting. I'm going to attempt to add a done= method to edit_line in shoes 3.2 (gtk) and see what happens. Names I've thought of done/finished/completed. Can always be changed later.

Allowing tabs into the edit_line is going to screw up keyboard navigation (which was already wonky). or the ML commenters focus issues.

ccoupe commented Aug 20, 2014

I'd like to suggest a different name instead of enter: That might be confusing to someone learning Shoes since it's not entering, it's exiting. I'm going to attempt to add a done= method to edit_line in shoes 3.2 (gtk) and see what happens. Names I've thought of done/finished/completed. Can always be changed later.

Allowing tabs into the edit_line is going to screw up keyboard navigation (which was already wonky). or the ML commenters focus issues.

@saveriomiroddi

This comment has been minimized.

Show comment
Hide comment
@saveriomiroddi

saveriomiroddi Aug 20, 2014

I don't know the internals (so, how hard/feasible it is), but I don't think that capturing "\n" on the change listener would be consistent ("\n" is not a change since it doesn't add anything to the field value) - I think a keypress listener at element level should be added instead.

I don't know the internals (so, how hard/feasible it is), but I don't think that capturing "\n" on the change listener would be consistent ("\n" is not a change since it doesn't add anything to the field value) - I think a keypress listener at element level should be added instead.

@PragTob

This comment has been minimized.

Show comment
Hide comment
@PragTob

PragTob Aug 20, 2014

Member

Hello everyone :)

So I'd be in favor of not doing anything that requires too much work here yet. E.g. I'm kind of fine with the behavior of edit_line to just do nothing.

I agree with the search field use case, for the meantime you could just listen for enter with a simple keypress, though.

I like the special option of doing something when enter is hit, similiar to click. But yeh, enter: is a suboptimal name as it could be confused with hitting enter.

I'll assign the 4.1.0 milestone since it seems like a new feature and I think shoes3 behavior is too specific here. If you disagree with 4.1.0, please let me know ;)

Member

PragTob commented Aug 20, 2014

Hello everyone :)

So I'd be in favor of not doing anything that requires too much work here yet. E.g. I'm kind of fine with the behavior of edit_line to just do nothing.

I agree with the search field use case, for the meantime you could just listen for enter with a simple keypress, though.

I like the special option of doing something when enter is hit, similiar to click. But yeh, enter: is a suboptimal name as it could be confused with hitting enter.

I'll assign the 4.1.0 milestone since it seems like a new feature and I think shoes3 behavior is too specific here. If you disagree with 4.1.0, please let me know ;)

@PragTob PragTob added this to the 4.1.0 milestone Aug 20, 2014

@KCErb

This comment has been minimized.

Show comment
Hide comment
@KCErb

KCErb Aug 20, 2014

Member

I agree with everything that's been said 😃 (don't name it enter, using the SWT keypress might be better than turning a single into a multi, 4.1).

So this discussion makes me realize that the core issue which got this discussion going is separate enough for a separate issue: #866.

Member

KCErb commented Aug 20, 2014

I agree with everything that's been said 😃 (don't name it enter, using the SWT keypress might be better than turning a single into a multi, 4.1).

So this discussion makes me realize that the core issue which got this discussion going is separate enough for a separate issue: #866.

@ccoupe

This comment has been minimized.

Show comment
Hide comment
@ccoupe

ccoupe Aug 23, 2014

I hope I don't annoy too many Shoes4 developers by fixing this in Shoes 3.2.15 (Linux, Windows, OSX). I decided to name the attribute 'finish'. Easily changed to whatever you folks prefer.

Shoes.app do
   stack do
      @el = edit_line do |e|
       para e.text+"\n"
    end
    @el.finish = proc { |slf| para "enterkey #{slf.text}\n" }
  end
end

ccoupe commented Aug 23, 2014

I hope I don't annoy too many Shoes4 developers by fixing this in Shoes 3.2.15 (Linux, Windows, OSX). I decided to name the attribute 'finish'. Easily changed to whatever you folks prefer.

Shoes.app do
   stack do
      @el = edit_line do |e|
       para e.text+"\n"
    end
    @el.finish = proc { |slf| para "enterkey #{slf.text}\n" }
  end
end
@jasonrclark

This comment has been minimized.

Show comment
Hide comment
@jasonrclark

jasonrclark Aug 26, 2014

Member

Not bothered at all here @ccoupe and I like finish as the name well enough. Thanks!

Member

jasonrclark commented Aug 26, 2014

Not bothered at all here @ccoupe and I like finish as the name well enough. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment