Oberon Community Platform Forum
October 14, 2019, 06:26:28 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: Word selection on double clicking  (Read 34735 times)
sage
Full Member
***
Posts: 170



WWW
« on: April 03, 2008, 02:27:33 PM »

Problem: When double clicking on words in any Bluebottle's editor, extra characters got selected.

Posible solution is to modify procedures FindPosWordLeft and FindPosWordRight that are in AosTextUtilities module in that way:
Code:
(** Find the position of the next word start to the left *)
PROCEDURE FindPosWordLeft*(utilreader: AosTexts.TextReader; pos : LONGINT) : LONGINT;
VAR ch : AosTexts.Char32;
BEGIN
utilreader.SetPosition(pos); utilreader.SetDirection(-1);
utilreader.ReadCh(ch);
WHILE IsAlphaNum(ch) & ~IsWhiteSpace(ch) & (ch # AosTexts.NewLineChar) & ~utilreader.eot DO utilreader.ReadCh(ch) END;
IF utilreader.eot THEN RETURN 0
ELSE RETURN utilreader.GetPosition() + 2
END
END FindPosWordLeft;

(** Find the position of the next word start to the right *)
PROCEDURE FindPosWordRight*(utilreader: AosTexts.TextReader; pos : LONGINT) : LONGINT;
VAR ch : AosTexts.Char32;
BEGIN
utilreader.SetPosition(pos); utilreader.SetDirection(1);
utilreader.ReadCh(ch);
WHILE IsAlphaNum(ch) & ~IsWhiteSpace(ch) & (ch # AosTexts.NewLineChar) & ~utilreader.eot DO utilreader.ReadCh(ch) END;
IF utilreader.eot THEN RETURN utilreader.text.GetLength()
ELSE RETURN utilreader.GetPosition()-1
END
END FindPosWordRight;

Thanks to BohdanT for initial hints for solving this problem  Smiley
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #1 on: April 04, 2008, 06:21:44 AM »

Also need to make a small correction in the procedure AosTextUtilities.IsAlphaNum.
Need to add a character "_"
Code:
(* Return true if the unicode character x is alpha numeric *)
PROCEDURE IsAlphaNum*(x:Char32): BOOLEAN;
BEGIN
RETURN (ORD("0") <= x) & (x <= ORD("9"))
OR (ORD("A") <= x) & (x <= ORD("Z") )
OR (ORD("a") <= x) & (x <= ORD("z") )
OR (x = ORD("_") )
END IsAlphaNum;
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #2 on: April 04, 2008, 08:13:06 AM »

Why should the character "_" be considered a alphanumeric character?
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #3 on: April 04, 2008, 08:44:24 AM »

I generally agree that improving the word selection is a good idea (it would also be nice to select the line when double-clicking on it after the last word on the line).

The suggested implementation has some problems, however. For Example:

CTRL-Left and CTRL-Right can be used to skip words. For this, FindPosWordLeft must really do what is stated in its comment, which is to find the next word start at the left side of the cursor position. The same applies for FindPosWordRight. Does not work with the suggested solution.

Also, the test (IsAlphaNum(ch) & ~IsWhitespace(ch) & (ch # AosTexts.NewLineChar)) does the same as IsAlphaNum(ch).

I think that we need to leave the FindPosWordLeft and FindPosWordRight procedures as they are and implement some additional procedure(s) that enable the correct selection of a word when double-clicking it.

Some more thoughts:

Since this kind of selection is really specific to selecy-by-double-click, the code should be located at the place where this is relevant -> WMTextView.Mod. Also, I suggest to implement a new procedure there that does the selection (and also implements the select-line when double-clicking at the end of the line). Also, that procedure can consider the "_" character as part of a word.

Does somebody here have the time/interest to implement this?
« Last Edit: April 04, 2008, 09:00:48 AM by staubesv » Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #4 on: April 04, 2008, 09:01:33 AM »

   
Delphi and VisualStudio believed symbol "_" as alphanumeric character when I am doing double click on the word or press CTRL-Left and CTRL-Right .
   
And last because I can write:
Code:
my_var: LONGINT;
Is my_var not one word?

PS: I do not understand why in Aos symbol "_" in Oberon font displayed as  "-"?
« Last Edit: April 04, 2008, 09:10:02 AM by BohdanT » Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #5 on: April 04, 2008, 09:14:47 AM »

"_" is not an alphanumeric character but can be considered a (legal) character of a word.

The original reason why "_" is displayed as "-" is that some people here didn't like identifiers that contain underscores. Personally, I would prefer the "_" to be displayed as "_". It seems that the Oberon Fonts just use the "wrong" glyph. When you use a different font (e.g. Vera), the underscores are displayed correctly.
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #6 on: April 04, 2008, 09:25:32 AM »

Then I propose to rename procedure IsAlphaNum IsAlphaNumAnd_:)
Because otherwise using the identifier symbols "_" it will not work correctly.

I myself, and not very often use this symbol, but if port ready sources (especially from C and C + +), it is often often occurs.
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #7 on: April 04, 2008, 09:48:16 AM »

For selecting words, we can implement new code that does something like

Code:
WHILE (AosTextUtilities.IsAlphaNum(ch) OR (ch = ORD("_")) DO ... END;

Also, this code would then not use AosTextUtilities.FindPosWordLeft/Right but implement the needed functionality itself (to implemented the select complete line feature, for example).
Logged
sage
Full Member
***
Posts: 170



WWW
« Reply #8 on: April 04, 2008, 09:48:41 AM »

Also, the test (IsAlphaNum(ch) & ~IsWhitespace(ch) & (ch # AosTexts.NewLineChar)) does the same as IsAlphaNum(ch).
You are absolutely right!
I think that we need to leave the FindPosWordLeft and FindPosWordRight procedures as they are and implement some additional procedure(s) that enable the correct selection of a word when double-clicking it.
That's right too!
Logged
sage
Full Member
***
Posts: 170



WWW
« Reply #9 on: April 04, 2008, 10:36:31 AM »

It also may be nice to select long white space areas on double clicking.
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #10 on: April 04, 2008, 10:40:02 AM »

Yes, selection of whitespace separating words would also be nice.
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #11 on: April 04, 2008, 12:02:47 PM »

Does somebody here have the time/interest to implement this? (select a word when double-clicking it, select whitespace when double-clicking it, select line if double-clicking the end of a line, to be implemented in WMTextView.Mod)
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #12 on: April 04, 2008, 12:52:26 PM »

Quote
select line if double-clicking the end of a line
I think it is better at the beginning of the line.
but still not bad to do a special column in which to display bookmarks and line numbers, and if you click on it, then select line (   
in the future add code collapse).
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #13 on: April 04, 2008, 01:00:03 PM »

I've just done some experiments with other applications (e.g. Notepad, Internet Explorer). They do almost the same as TextView currently does: The text selection starts at the first character of the selected word and ends at the last whitespace before next word starts... Somehow, this makes sense (can delete a word, whitespace is optimal after deletion). Should we change it at all?
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #14 on: April 04, 2008, 01:35:38 PM »

Quote
I've just done some experiments with other applications (e.g. Notepad, Internet Explorer).

 Notepad, Internet Explorer, Microsoft Word, FireFox - This is not programmers editors!!!
 Please try VisualStudio, Delphi, Eclipse etc...

I'm write next:
Code:
PROCEDURE FindPosWordLeft*(utilreader: AosTexts.TextReader; pos : LONGINT) : LONGINT;
VAR ch : AosTexts.Char32;
BEGIN
utilreader.SetPosition(pos); utilreader.SetDirection(-1);
utilreader.ReadCh(ch);
IF (ch = AosTexts.NewLineChar) THEN utilreader.ReadCh(ch);END;

IF AosTextUtilities.IsAlphaNum(ch)OR(ch=ORD("_")) THEN
WHILE (AosTextUtilities.IsAlphaNum(ch))OR(ch=ORD("_")) DO utilreader.ReadCh(ch) END;
RETURN utilreader.GetPosition() + 2
ELSIF AosTextUtilities.IsWhiteSpace(ch) THEN
WHILE AosTextUtilities.IsWhiteSpace(ch) DO utilreader.ReadCh(ch) END;
RETURN utilreader.GetPosition() + 2
ELSE   
WHILE (ch#ORD("_"))&(~AosTextUtilities.IsAlphaNum(ch))&(~AosTextUtilities.IsWhiteSpace(ch))&(ch # AosTexts.NewLineChar) DO utilreader.ReadCh(ch) END;
RETURN utilreader.GetPosition() + 2
END;
END FindPosWordLeft;

PROCEDURE FindPosWordRight*(utilreader: AosTexts.TextReader; pos : LONGINT) : LONGINT;
VAR ch : AosTexts.Char32;
BEGIN
utilreader.SetPosition(pos); utilreader.SetDirection(1);
utilreader.ReadCh(ch);
IF (ch = AosTexts.NewLineChar) THEN utilreader.SetPosition(pos-1); utilreader.ReadCh(ch);END;

IF AosTextUtilities.IsAlphaNum(ch)OR(ch=ORD("_")) THEN
WHILE (AosTextUtilities.IsAlphaNum(ch))OR(ch=ORD("_")) DO utilreader.ReadCh(ch) END;
RETURN utilreader.GetPosition() - 1
ELSIF AosTextUtilities.IsWhiteSpace(ch) THEN
WHILE AosTextUtilities.IsWhiteSpace(ch) DO utilreader.ReadCh(ch) END;
RETURN utilreader.GetPosition() - 1
ELSE
WHILE (ch#ORD("_"))&(~AosTextUtilities.IsAlphaNum(ch))&(~AosTextUtilities.IsWhiteSpace(ch))&(ch # AosTexts.NewLineChar) DO utilreader.ReadCh(ch) END;
RETURN utilreader.GetPosition() - 1
END;
END FindPosWordRight;
Logged
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!