From: Hamish <dmishd@gmail.com>
To: sup-devel <sup-devel@rubyforge.org>
Subject: Re: [sup-devel] [BRANCH] Ctrl-W behaviour
Date: Tue, 22 Feb 2011 17:01:29 +0000 [thread overview]
Message-ID: <1298393768-sup-7839@whisper> (raw)
In-Reply-To: <1298251460-sup-4333@whisper>
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
next prev parent reply other threads:[~2011-02-22 17:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-21 1:29 Hamish
2011-02-22 17:01 ` Hamish [this message]
2011-02-23 13:19 ` Alvaro Herrera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1298393768-sup-7839@whisper \
--to=dmishd@gmail.com \
--cc=sup-devel@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox