summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2014-10-16 12:15:12 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2014-10-16 12:15:12 +0000
commit4774c261826b04efdf045497091090aa7449a021 (patch)
treea9ddfaa851eef85a1223222bcf78ed1f9165223e /src
parent5403c1760626b3fbb55badf93d772f35b7490737 (diff)
Fix word select dragging bug in text input (STR #3014).
Thanks to Evan Laforge for spotting this and supplying a patch. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10383 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Input_.cxx48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/Fl_Input_.cxx b/src/Fl_Input_.cxx
index 4f040b63c..a9caa5262 100644
--- a/src/Fl_Input_.cxx
+++ b/src/Fl_Input_.cxx
@@ -428,16 +428,17 @@ static int isword(char c) {
/**
Finds the end of a word.
- This call calculates the end of a word based on the given
- index \p i. Calling this function repeatedly will move
- forwards to the end of the text.
-
+ Returns the index after the last byte of a space-separated word. This
+ first skips spaces, and then non-spaces, so if you call it repeatedly
+ you will move forwards to the end of the text.
+
+ Note that this is inconsistent with line_end().
+
\param [in] i starting index for the search
\return end of the word
*/
int Fl_Input_::word_end(int i) const {
if (input_type() == FL_SECRET_INPUT) return size();
- //while (i < size() && !isword(index(i))) i++;
while (i < size() && !isword(index(i))) i++;
while (i < size() && isword(index(i))) i++;
return i;
@@ -446,17 +447,18 @@ int Fl_Input_::word_end(int i) const {
/**
Finds the start of a word.
- This call calculates the start of a word based on the given
- index \p i. Calling this function repeatedly will move
- backwards to the beginning of the text.
-
+ Returns the index of the first byte of a space-separated word.
+ If the index is already at the beginning of the word, it will find the
+ beginning of the previous word, so if you call it repeatedly you will
+ move backwards to the beginning of the text.
+
+ Note that this is inconsistent with line_start().
+
\param [in] i starting index for the search
- \return start of the word
+ \return start of the word, or previous word
*/
int Fl_Input_::word_start(int i) const {
if (input_type() == FL_SECRET_INPUT) return 0;
-// if (i >= size() || !isword(index(i)))
-// while (i > 0 && !isword(index(i-1))) i--;
while (i > 0 && !isword(index(i-1))) i--;
while (i > 0 && isword(index(i-1))) i--;
return i;
@@ -518,6 +520,20 @@ int Fl_Input_::line_start(int i) const {
} else return j;
}
+static int strict_word_start(const char *s, int i, int itype) {
+ if (itype == FL_SECRET_INPUT) return 0;
+ while (i > 0 && !isspace(s[i-1]))
+ i--;
+ return i;
+}
+
+static int strict_word_end(const char *s, int len, int i, int itype) {
+ if (itype == FL_SECRET_INPUT) return len;
+ while (i < len && !isspace(s[i]))
+ i++;
+ return i;
+}
+
/**
Handles mouse clicks and mouse moves.
\todo Add comment and parameters
@@ -571,16 +587,16 @@ void Fl_Input_::handle_mouse(int X, int Y, int /*W*/, int /*H*/, int drag) {
newpos = line_end(newpos);
newmark = line_start(newmark);
} else {
- newpos = word_end(newpos);
- newmark = word_start(newmark);
+ newpos = strict_word_end(value(), size(), newpos, input_type());
+ newmark = strict_word_start(value(), newmark, input_type());
}
} else {
if (Fl::event_clicks() > 1) {
newpos = line_start(newpos);
newmark = line_end(newmark);
} else {
- newpos = word_start(newpos);
- newmark = word_end(newmark);
+ newpos = strict_word_start(value(), newpos, input_type());
+ newmark = strict_word_end(value(), size(), newmark, input_type());
}
}
// if the multiple click does not increase the selection, revert