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
This commit is contained in:
Albrecht Schlosser 2014-10-16 12:15:12 +00:00
parent 5403c17606
commit 4774c26182
2 changed files with 39 additions and 22 deletions

13
CHANGES
View File

@ -1,11 +1,12 @@
CHANGES IN FLTK 1.3.3 RELEASED: MMM DD YYYY
- Mac OS X: fixed fl_read_image() and Fl_Paged_Device::print_window_part()
when using a 'retina' display.
- Fix word select dragging bug in text input (STR #3014).
- Mac OS X: fixed fl_read_image() and Fl_Paged_Device::print_window_part()
when using a 'retina' display.
- on Linux/Unix, class Fl_Native_File_Chooser uses file dialogs of the Gnome
environment (provided by the libgtk dynamic library), when this is available,
and falls back to FLTK's Fl_File_Chooser, when it's not (STR #3088).
- added class Fl_Copy_Surface allowing to copy graphical data to the clipboard
- added class Fl_Copy_Surface allowing to copy graphical data to the clipboard
in a cross-platform way (STR #3058).
- added support for pasting graphical data from the clipboard to an FLTK widget.
- added class Fl_Image_Surface allowing to draw into an Fl_Image object.
@ -28,8 +29,8 @@ CHANGES IN FLTK 1.3.3 RELEASED: MMM
the output file extension gets changed when the user modifies the output file type.
- Removed the now unused src/Fl_mac.cxx
- Fixed various Mac specific opengl issues (STR #2944)
- Added new method Fl_Widget::top_window() (STR #2948)
- Added new method Fl_Widget::top_window_offset() (part of STR #2944)
- Added new method Fl_Widget::top_window() (STR #2948)
- Added new method Fl_Widget::top_window_offset() (part of STR #2944)
- Added ability to get notifications whenever the clipboard changes (STR#2636)
New methods:
Fl::add_clipboard_notify(Fl_Clipboard_Notify_Handler h, void *data = 0)
@ -42,7 +43,7 @@ CHANGES IN FLTK 1.3.3 RELEASED: MMM
(To enable the following ABI features, put: #define FLTK_ABI_VERSION 10303
at the top of your FL/Enumerations.H and rebuild FLTK and your app)
- added Fl_Window::shape(const Fl_Image*) to create arbitrarily-shaped windows
- added Fl_Window::shape(const Fl_Image*) to create arbitrarily-shaped windows
- Made Fl_Help_View::handle() public and Fl_Help_View::draw() protected
to enable inheritance and for consistency (STR #2834).
Note: both methods were private.

View File

@ -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