[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sup-devel] [BRANCH] Ctrl-W behaviour
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