* [sup-devel] [BRANCH] Ctrl-W behaviour
@ 2011-02-21 1:29 Hamish
2011-02-22 17:01 ` Hamish
0 siblings, 1 reply; 3+ messages in thread
From: Hamish @ 2011-02-21 1:29 UTC (permalink / raw)
To: sup-devel
I use Ctrl-W when deleting labels from a thread, and it's been a minor
annoyance that this is slightly broken - when there is a space before
the cursor, Ctrl-W will just delete the space, and you need to press
Ctrl-W a second time to delete the word aswell. This is not how I'm used
to it working in vim or on the command line.
So I've now had a go at fixing it, in the branch called ctrl_w - just
one commit so far, and it took quite a bit of farting around to get this
far. I'll review it when it's not the early hours of the morning and
merge it into next at that point.
Please have a go and see if you can get any strange behaviour - I had
some strange behaviour with single-letter labels, but I seem to have
fixed that ...
Hamish Downer
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [sup-devel] [BRANCH] Ctrl-W behaviour
2011-02-21 1:29 [sup-devel] [BRANCH] Ctrl-W behaviour Hamish
@ 2011-02-22 17:01 ` Hamish
2011-02-23 13:19 ` Alvaro Herrera
0 siblings, 1 reply; 3+ messages in thread
From: Hamish @ 2011-02-22 17:01 UTC (permalink / raw)
To: sup-devel
Excerpts from Hamish's message of Mon Feb 21 01:29:20 +0000 2011:
> I use Ctrl-W when deleting labels from a thread, and it's been a minor
> annoyance that this is slightly broken - when there is a space before
> the cursor, Ctrl-W will just delete the space, and you need to press
> Ctrl-W a second time to delete the word aswell. This is not how I'm used
> to it working in vim or on the command line.
I've now merged this into next. I forgot to put the patches in email
last night, so I've put the branch diff at the end of this email.
Hamish Downer
diff --git a/lib/sup/textfield.rb b/lib/sup/textfield.rb
index a3d002a..343e450 100644
--- a/lib/sup/textfield.rb
+++ b/lib/sup/textfield.rb
@@ -120,6 +120,9 @@ class TextField
nop
Ncurses::Form::REQ_BEG_FIELD
when ?\C-w.ord
+ while action = remove_extra_space
+ Ncurses::Form.form_driver @form, action
+ end
Ncurses::Form.form_driver @form, Ncurses::Form::REQ_PREV_CHAR
Ncurses::Form.form_driver @form, Ncurses::Form::REQ_DEL_WORD
when Ncurses::KEY_UP, Ncurses::KEY_DOWN
@@ -167,6 +170,40 @@ private
end
end
+ def remove_extra_space
+ return nil unless @field
+
+ Ncurses::Form.form_driver @form, Ncurses::Form::REQ_VALIDATION
+ x = Ncurses.curx
+ v = @field.field_buffer(0).gsub(/^\s+|\s+$/, "")
+ v_index = x - @question.length
+
+ # at start of line
+ if v_index < 1
+ nil
+ ## cursor <= end of text
+ elsif v_index < v.length
+ # is the character before the cursor a space?
+ if v[v_index-1] == ?\s
+ # if there is a non-space char under cursor then go back
+ if v[v_index] != ?\s
+ Ncurses::Form::REQ_PREV_CHAR
+ # otherwise delete the space
+ else
+ Ncurses::Form::REQ_DEL_PREV
+ end
+ else
+ nil
+ end
+ elsif v_index == v.length
+ # at end of string, with non-space before us
+ nil
+ else
+ # trailing spaces
+ Ncurses::Form::REQ_PREV_CHAR
+ end
+ end
+
def set_cursed_value v
@field.set_field_buffer 0, v
end
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [sup-devel] [BRANCH] Ctrl-W behaviour
2011-02-22 17:01 ` Hamish
@ 2011-02-23 13:19 ` Alvaro Herrera
0 siblings, 0 replies; 3+ messages in thread
From: Alvaro Herrera @ 2011-02-23 13:19 UTC (permalink / raw)
To: sup-devel
Excerpts from Hamish's message of mar feb 22 14:01:29 -0300 2011:
> Excerpts from Hamish's message of Mon Feb 21 01:29:20 +0000 2011:
> > I use Ctrl-W when deleting labels from a thread, and it's been a minor
> > annoyance that this is slightly broken - when there is a space before
> > the cursor, Ctrl-W will just delete the space, and you need to press
> > Ctrl-W a second time to delete the word aswell. This is not how I'm used
> > to it working in vim or on the command line.
>
> I've now merged this into next. I forgot to put the patches in email
> last night, so I've put the branch diff at the end of this email.
I've been using this and it works great. I was annoyed by the original
behavior too.
--
Álvaro Herrera <alvherre@alvh.no-ip.org>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-02-23 13:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-21 1:29 [sup-devel] [BRANCH] Ctrl-W behaviour Hamish
2011-02-22 17:01 ` Hamish
2011-02-23 13:19 ` Alvaro Herrera
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox