Index: textarea.c
===================================================================
--- textarea.c (Revision 13970)
+++ textarea.c (Arbeitskopie)
@@ -121,6 +121,7 @@
static bool textarea_set_caret_xy(struct text_area *ta, int x, int y);
static bool textarea_scroll_visible(struct text_area *ta);
static bool textarea_select(struct text_area *ta, int c_start, int c_end);
+static bool textarea_select_fragment (struct text_area *ta);
static void textarea_normalise_text(struct text_area *ta,
unsigned int b_start, unsigned int b_len);
@@ -1335,6 +1336,12 @@
ta->vis_height);
}
}
+ else if( mouse & BROWSER_MOUSE_DOUBLE_CLICK ){
+ if ( !(ta->flags & TEXTAREA_READONLY) ){
+ textarea_set_caret_xy( ta, x, y );
+ return textarea_select_fragment( ta );
+ }
+ }
else if (mouse & BROWSER_MOUSE_DRAG_1) {
ta->drag_start_char = textarea_get_xy_offset(ta, x, y);
if (!(ta->flags & TEXTAREA_READONLY))
@@ -1406,6 +1413,47 @@
/**
+ * Selects a text fragment, relative to current caret position.
+ *
+ * \param ta Text area
+ * \return true on success false otherwise
+ */
+static bool textarea_select_fragment(struct text_area * ta )
+{
+ int c_pos, start_pos, end_pos;
+ static const char * sep = "/.\r\n";
+
+ c_pos = textarea_get_caret(ta);
+ if( c_pos < 0 ){
+ return( false );
+ }
+
+ start_pos = c_pos;
+ while(start_pos > 0 ){
+ if(strchr(sep, ta->text[start_pos]) != NULL){
+ start_pos++;
+ break;
+ }
+ start_pos--;
+ }
+
+ end_pos = c_pos;
+ while(end_pos < (int)ta->text_len){
+ if(strchr(sep, ta->text[end_pos]) != NULL){
+ break;
+ }
+ end_pos++;
+ }
+
+ if(start_pos < end_pos){
+ textarea_select(ta, start_pos, end_pos);
+ return( true );
+ }
+
+ return( false );
+}
+
+/**
* Normalises any line endings within the text, replacing CRLF or CR with
* LF as necessary. If the textarea is single line, then all linebreaks are
* converted into spaces.
Hello,
this patch adds text-fragment selection on textarea double-click.
Is it of any interest to others? If so, I hope it will be commited, or
at least discussed/reviewed :)
Greets,
Ole
No comments:
Post a Comment