FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
STTextBox/ST.Library.UI.STTextBox/STTextBox.KeyEvent.cs at main · hobosoft/STTextBox · GitHub
hobosoft
/
STTextBox
Public
forked from
DebugST/STTextBox
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
STTextBox
/
ST.Library.UI.STTextBox
/
STTextBox.KeyEvent.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
524 lines (508 loc) · 21.1 KB
Breadcrumbs
STTextBox
/
ST.Library.UI.STTextBox
/
STTextBox.KeyEvent.cs
Copy path
File metadata and controls
524 lines (508 loc) · 21.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Text
;
using
System
.
Windows
.
Forms
;
using
System
.
Text
.
RegularExpressions
;
namespace
ST
.
Library
.
UI
.
STTextBox
{
public
partial
class
STTextBox
{
protected
override
bool
ProcessCmdKey
(
ref
Message
msg
,
Keys
keyData
)
{
switch
(
keyData
)
{
case
Keys
.
Back
:
this
.
ProcessBackSpaceKey
(
)
;
return
true
;
case
Keys
.
Tab
:
this
.
ProcessTabKey
(
)
;
return
true
;
case
Keys
.
Enter
:
this
.
ProcessEnter
(
)
;
return
true
;
//========================================================
case
Keys
.
Left
:
this
.
ProcessLeftKey
(
false
)
;
return
true
;
case
Keys
.
Right
:
this
.
ProcessRightKey
(
false
)
;
return
true
;
case
Keys
.
Up
:
this
.
ProcessUpKey
(
false
)
;
return
true
;
case
Keys
.
Down
:
this
.
ProcessDownKey
(
false
)
;
return
true
;
case
Keys
.
Home
:
this
.
ProcessHomeKey
(
false
)
;
return
true
;
case
Keys
.
End
:
this
.
ProcessEndKey
(
false
)
;
return
true
;
case
Keys
.
PageUp
:
this
.
ProcessPageUpKey
(
false
)
;
return
true
;
case
Keys
.
PageDown
:
this
.
ProcessPageDownKey
(
false
)
;
return
true
;
//========================================================
case
Keys
.
Shift
|
Keys
.
Tab
:
this
.
ProcessShiftTabKey
(
)
;
return
true
;
case
Keys
.
Shift
|
Keys
.
Up
:
this
.
ProcessUpKey
(
true
)
;
return
true
;
case
Keys
.
Shift
|
Keys
.
Down
:
this
.
ProcessDownKey
(
true
)
;
return
true
;
case
Keys
.
Shift
|
Keys
.
Left
:
this
.
ProcessLeftKey
(
true
)
;
return
true
;
case
Keys
.
Shift
|
Keys
.
Right
:
this
.
ProcessRightKey
(
true
)
;
return
true
;
case
Keys
.
Shift
|
Keys
.
Home
:
this
.
ProcessHomeKey
(
true
)
;
return
true
;
case
Keys
.
Shift
|
Keys
.
End
:
this
.
ProcessEndKey
(
true
)
;
return
true
;
case
Keys
.
Shift
|
Keys
.
PageUp
:
this
.
ProcessPageUpKey
(
true
)
;
return
true
;
case
Keys
.
Shift
|
Keys
.
PageDown
:
this
.
ProcessPageDownKey
(
true
)
;
return
true
;
//========================================================
case
Keys
.
Control
|
Keys
.
A
:
this
.
SelectAll
(
)
;
return
true
;
case
Keys
.
Control
|
Keys
.
C
:
this
.
Copy
(
)
;
return
true
;
case
Keys
.
Control
|
Keys
.
X
:
this
.
Cut
(
)
;
return
true
;
case
Keys
.
Control
|
Keys
.
V
:
this
.
Paste
(
)
;
return
true
;
case
Keys
.
Control
|
Keys
.
Z
:
this
.
Undo
(
)
;
return
true
;
case
Keys
.
Control
|
Keys
.
Y
:
this
.
Redo
(
)
;
return
true
;
}
return
base
.
ProcessCmdKey
(
ref
msg
,
keyData
)
;
}
protected
override
void
OnKeyPress
(
KeyPressEventArgs
e
)
{
base
.
OnKeyPress
(
e
)
;
if
(
e
.
KeyChar
<
32
/* || e.KeyChar > 126*/
)
{
return
;
}
this
.
EnterText
(
e
.
KeyChar
.
ToString
(
)
)
;
}
//==================================================================================
private
void
ProcessEnter
(
)
{
var
c
=
m_core
;
string
strText
=
"
\r
\n
"
;
if
(
this
.
_AutoIndent
)
{
strText
+=
Regex
.
Match
(
c
.
TextManager
[
c
.
TextManager
.
GetLineIndexFromCharIndex
(
c
.
Caret
.
IndexOfChar
)
]
.
RawString
,
@"^[ \t]+"
//Space,TAB
)
.
Value
;
}
this
.
EnterText
(
strText
)
;
}
private
void
ProcessTabKey
(
)
{
var
c
=
m_core
;
int
nIndexStartLine
=
0
,
nIndexEndLine
=
0
;
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
nIndexStartLine
=
c
.
TextManager
.
GetLineIndexFromCharIndex
(
c
.
Selection
.
StartIndex
)
;
nIndexEndLine
=
c
.
TextManager
.
GetLineIndexFromCharIndex
(
c
.
Selection
.
EndIndex
)
;
}
if
(
nIndexStartLine
==
nIndexEndLine
)
{
if
(
!
this
.
_TabToSpace
)
{
this
.
EnterText
(
"
\t
"
)
;
}
else
{
float
fSpaceCount
=
c
.
ITextBoxRender
.
GetTabSpaceCount
(
c
.
ITextView
.
GetCurrentCharOffset
(
)
,
this
.
_TabSize
)
;
this
.
EnterText
(
""
.
PadLeft
(
(
int
)
Math
.
Ceiling
(
fSpaceCount
)
)
)
;
}
}
else
{
string
strInsert
=
this
.
_TabToSpace
?
""
.
PadLeft
(
this
.
_TabSize
)
:
"
\t
"
;
var
histories
=
c
.
TextManager
.
InsertAtStart
(
nIndexStartLine
,
nIndexEndLine
-
nIndexStartLine
+
1
,
strInsert
)
;
c
.
ITextHistory
.
SetHistory
(
histories
)
;
var
lineStart
=
c
.
TextManager
[
nIndexStartLine
]
;
var
lineEnd
=
c
.
TextManager
[
nIndexEndLine
]
;
c
.
Selection
.
SetSelection
(
lineStart
.
IndexOfFirstChar
,
lineEnd
.
IndexOfFirstChar
+
lineEnd
.
GetLengthWithoutNewline
(
)
)
;
c
.
Caret
.
IndexOfChar
=
c
.
Selection
.
EndIndex
;
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
}
}
private
void
ProcessShiftTabKey
(
)
{
var
c
=
m_core
;
int
nIndexStartLine
=
0
,
nIndexEndLine
=
0
;
nIndexStartLine
=
c
.
TextManager
.
GetLineIndexFromCharIndex
(
c
.
Selection
.
StartIndex
)
;
nIndexEndLine
=
c
.
TextManager
.
GetLineIndexFromCharIndex
(
c
.
Selection
.
EndIndex
)
;
if
(
nIndexStartLine
==
nIndexEndLine
)
{
var
line
=
c
.
TextManager
[
nIndexStartLine
]
;
for
(
int
i
=
0
;
i
<
line
.
RawString
.
Length
;
i
++
)
{
switch
(
line
.
RawString
[
i
]
)
{
case
' '
:
case
'
\t
'
:
continue
;
default
:
break
;
}
if
(
i
==
0
||
i
+
line
.
IndexOfFirstChar
<
c
.
Selection
.
StartIndex
)
{
return
;
}
}
}
var
histories
=
c
.
TextManager
.
TrimStartTab
(
nIndexStartLine
,
nIndexEndLine
-
nIndexStartLine
+
1
,
this
.
_TabSize
)
;
c
.
ITextHistory
.
SetHistory
(
histories
.
ToArray
(
)
)
;
var
lineStart
=
c
.
TextManager
[
nIndexStartLine
]
;
var
lineEnd
=
c
.
TextManager
[
nIndexEndLine
]
;
c
.
Selection
.
SetSelection
(
lineStart
.
IndexOfFirstChar
,
lineEnd
.
IndexOfFirstChar
+
lineEnd
.
GetLengthWithoutNewline
(
)
)
;
c
.
Caret
.
IndexOfChar
=
c
.
Selection
.
EndIndex
;
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
}
private
void
ProcessBackSpaceKey
(
)
{
var
c
=
m_core
;
if
(
c
.
Caret
.
IndexOfChar
==
0
&&
c
.
Selection
.
IsEmptySelection
)
{
return
;
}
if
(
c
.
Selection
.
IsEmptySelection
)
{
//c.Selection.SetIndex(c.Caret.IndexOfChar);
int
nLineIndex
=
c
.
TextManager
.
GetLineIndexFromCharIndex
(
c
.
Caret
.
IndexOfChar
)
;
TextLine
stLine
=
c
.
TextManager
[
nLineIndex
]
;
if
(
c
.
Caret
.
IndexOfChar
==
stLine
.
IndexOfFirstChar
)
{
//if the index is the line start index
stLine
=
c
.
TextManager
[
nLineIndex
-
1
]
;
//c.Selection.StartIndex -= stLine.RawString.Length - stLine.GetLengthWithoutNewline();
c
.
Selection
.
SetSelection
(
c
.
Caret
.
IndexOfChar
,
c
.
Caret
.
IndexOfChar
-
(
stLine
.
RawString
.
Length
-
stLine
.
GetLengthWithoutNewline
(
)
)
)
;
}
else
{
int
nIndex
=
stLine
.
IndexOfFirstChar
;
c
.
IGraphemeSplitter
.
Each
(
stLine
.
RawString
,
(
str
,
nStart
,
nLen
)
=>
{
if
(
nIndex
+
nLen
>=
c
.
Caret
.
IndexOfChar
)
{
return
false
;
}
nIndex
+=
nLen
;
return
true
;
}
)
;
//c.Selection.StartIndex = nIndex;
c
.
Selection
.
SetSelection
(
nIndex
,
c
.
Caret
.
IndexOfChar
)
;
}
}
this
.
EnterText
(
""
)
;
}
private
void
ProcessUpKey
(
bool
bShiftDown
)
{
var
c
=
m_core
;
if
(
c
.
Scroll
.
YValue
==
0
&&
c
.
Caret
.
Y
-
m_core
.
ViewRectangle
.
Y
<
m_core
.
LineHeight
)
{
return
;
}
c
.
Caret
.
Y
-=
c
.
LineHeight
;
// c.ITextRender.GetFontHeight();
var
fi
=
c
.
ITextView
.
FindFromPoint
(
c
.
Caret
.
Location
)
;
if
(
!
c
.
Caret
.
CopyFromFindInfo
(
fi
)
)
{
return
;
}
bool
bRedraw
=
false
;
if
(
bShiftDown
)
{
c
.
Selection
.
SetSelection
(
c
.
Caret
.
IndexOfChar
)
;
bRedraw
=
true
;
}
else
{
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
bRedraw
=
true
;
c
.
Caret
.
IndexOfChar
=
c
.
Selection
.
StartIndex
;
}
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
}
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
if
(
c
.
ITextView
.
ScrollToCaret
(
)
||
bRedraw
)
{
this
.
Invalidate
(
)
;
}
}
private
void
ProcessDownKey
(
bool
bShiftDown
)
{
var
c
=
m_core
;
if
(
c
.
Caret
.
IndexOfLine
>=
c
.
TextManager
.
LineCount
-
1
)
{
//return;
}
c
.
Caret
.
Y
+=
c
.
LineHeight
;
// c.ITextRender.GetFontHeight();
var
fi
=
c
.
ITextView
.
FindFromPoint
(
c
.
Caret
.
Location
)
;
if
(
!
c
.
Caret
.
CopyFromFindInfo
(
fi
)
)
{
return
;
}
bool
bRedraw
=
false
;
if
(
bShiftDown
)
{
c
.
Selection
.
SetSelection
(
c
.
Caret
.
IndexOfChar
)
;
bRedraw
=
true
;
}
else
{
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
bRedraw
=
true
;
c
.
Caret
.
IndexOfChar
=
c
.
Selection
.
EndIndex
;
}
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
}
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
if
(
c
.
ITextView
.
ScrollToCaret
(
)
||
bRedraw
)
{
this
.
Invalidate
(
)
;
}
}
private
void
ProcessLeftKey
(
bool
bShiftDown
)
{
var
c
=
m_core
;
bool
bRedraw
=
false
;
if
(
bShiftDown
)
{
var
nIndex
=
c
.
TextBox
.
FindLeftIndex
(
c
.
Caret
.
IndexOfChar
)
;
if
(
nIndex
==
c
.
Caret
.
IndexOfChar
)
{
return
;
}
c
.
Caret
.
IndexOfChar
=
nIndex
;
c
.
Selection
.
SetSelection
(
c
.
Caret
.
IndexOfChar
)
;
bRedraw
=
true
;
}
else
{
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
bRedraw
=
true
;
c
.
Caret
.
IndexOfChar
=
c
.
Selection
.
StartIndex
;
}
else
{
var
nIndex
=
c
.
TextBox
.
FindLeftIndex
(
c
.
Caret
.
IndexOfChar
)
;
if
(
nIndex
==
c
.
Caret
.
IndexOfChar
)
{
return
;
}
c
.
Caret
.
IndexOfChar
=
nIndex
;
}
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
}
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
if
(
c
.
ITextView
.
ScrollToCaret
(
)
||
bRedraw
)
{
this
.
Invalidate
(
)
;
}
}
private
void
ProcessRightKey
(
bool
bShiftDown
)
{
var
c
=
m_core
;
bool
bRedraw
=
false
;
if
(
bShiftDown
)
{
var
nIndex
=
c
.
TextBox
.
FindRightIndex
(
c
.
Caret
.
IndexOfChar
)
;
if
(
nIndex
==
c
.
Caret
.
IndexOfChar
)
{
return
;
}
c
.
Caret
.
IndexOfChar
=
nIndex
;
c
.
Selection
.
SetSelection
(
nIndex
)
;
bRedraw
=
true
;
}
else
{
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
bRedraw
=
true
;
c
.
Caret
.
IndexOfChar
=
c
.
Selection
.
EndIndex
;
}
else
{
var
nIndex
=
c
.
TextBox
.
FindRightIndex
(
c
.
Caret
.
IndexOfChar
)
;
if
(
nIndex
==
c
.
Caret
.
IndexOfChar
)
{
return
;
}
c
.
Caret
.
IndexOfChar
=
nIndex
;
}
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
}
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
if
(
c
.
ITextView
.
ScrollToCaret
(
)
||
bRedraw
)
{
this
.
Invalidate
(
)
;
}
}
private
void
ProcessHomeKey
(
bool
bShiftDown
)
{
var
c
=
m_core
;
bool
bRedraw
=
false
;
var
stLine
=
c
.
TextManager
.
GetLineFromCharIndex
(
c
.
Caret
.
IndexOfChar
)
;
c
.
Caret
.
IndexOfChar
=
stLine
.
IndexOfFirstChar
;
if
(
bShiftDown
)
{
c
.
Selection
.
SetSelection
(
c
.
Caret
.
IndexOfChar
)
;
bRedraw
=
true
;
}
else
{
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
bRedraw
=
true
;
}
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
}
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
if
(
c
.
ITextView
.
ScrollToCaret
(
)
||
bRedraw
)
{
this
.
Invalidate
(
)
;
}
}
private
void
ProcessEndKey
(
bool
bShiftDown
)
{
var
c
=
m_core
;
bool
bRedraw
=
false
;
var
stLine
=
c
.
TextManager
.
GetLineFromCharIndex
(
c
.
Caret
.
IndexOfChar
)
;
//c.Caret.IndexOfChar = stLine.IndexOfFirstChar + stLine.RawString.Length;
c
.
Caret
.
IndexOfChar
=
stLine
.
IndexOfFirstChar
+
stLine
.
GetLengthWithoutNewline
(
)
;
if
(
bShiftDown
)
{
c
.
Selection
.
SetSelection
(
c
.
Caret
.
IndexOfChar
)
;
bRedraw
=
true
;
}
else
{
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
bRedraw
=
true
;
}
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
}
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
if
(
c
.
ITextView
.
ScrollToCaret
(
)
||
bRedraw
)
{
this
.
Invalidate
(
)
;
}
}
private
void
ProcessPageUpKey
(
bool
bShiftDown
)
{
var
c
=
m_core
;
if
(
c
.
Scroll
.
YValue
==
0
)
{
return
;
}
int
nCurrentLineCount
=
this
.
Height
/
c
.
LineHeight
;
c
.
Scroll
.
YValue
-=
nCurrentLineCount
;
if
(
c
.
Scroll
.
YValue
<
0
)
{
c
.
Scroll
.
YValue
=
0
;
c
.
Caret
.
Y
=
0
;
}
var
fi
=
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
Location
)
;
// c.ITextView.FindFromPoint(c.Caret.Location);
if
(
!
fi
.
Find
)
{
return
;
}
//c.Caret.CopyFromFindInfo(fi);
if
(
bShiftDown
)
{
c
.
Selection
.
SetSelection
(
c
.
Caret
.
IndexOfChar
)
;
}
else
{
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
this
.
Invalidate
(
)
;
}
else
{
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
}
}
//c.ITextView.SetCaretPostion(c.Caret.X, c.Caret.Y);
this
.
Invalidate
(
)
;
}
private
void
ProcessPageDownKey
(
bool
bShiftDown
)
{
var
c
=
m_core
;
if
(
c
.
Scroll
.
YValue
==
c
.
Scroll
.
MaxYValue
)
{
return
;
}
int
nCurrentLineCount
=
this
.
Height
/
c
.
LineHeight
;
c
.
Scroll
.
YValue
+=
nCurrentLineCount
;
if
(
c
.
Scroll
.
YValue
>
c
.
Scroll
.
MaxYValue
)
{
c
.
Scroll
.
YValue
=
c
.
Scroll
.
MaxYValue
;
}
var
fi
=
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
Location
)
;
// c.ITextView.FindFromPoint(c.Caret.Location);
if
(
!
fi
.
Find
)
{
return
;
}
//c.Caret.CopyFromFindInfo(fi);
if
(
bShiftDown
)
{
c
.
Selection
.
SetSelection
(
c
.
Caret
.
IndexOfChar
)
;
}
else
{
if
(
!
c
.
Selection
.
IsEmptySelection
)
{
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
this
.
Invalidate
(
)
;
}
else
{
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
}
}
//c.ITextView.SetCaretPostion(c.Caret.X, c.Caret.Y);
this
.
Invalidate
(
)
;
}
private
void
EnterText
(
string
strText
)
{
var
c
=
m_core
;
var
history
=
c
.
TextManager
.
SetText
(
c
.
Selection
.
StartIndex
,
c
.
Selection
.
Length
,
strText
)
;
if
(
history
!=
TextHistoryRecord
.
Empty
)
{
c
.
ITextHistory
.
SetHistory
(
new
TextHistoryRecord
[
]
{
history
}
)
;
}
c
.
Caret
.
IndexOfChar
=
c
.
Selection
.
StartIndex
+
strText
.
Length
;
c
.
ITextView
.
SetCaretPostion
(
c
.
Caret
.
IndexOfChar
)
;
c
.
Selection
.
SetIndex
(
c
.
Caret
.
IndexOfChar
)
;
c
.
ITextView
.
ScrollToCaret
(
)
;
//this.Invalidate();
}
//==================================================
private
int
FindRightIndex
(
int
nIndex
)
{
var
c
=
m_core
;
if
(
nIndex
>=
c
.
TextManager
.
TextLength
)
{
return
c
.
TextManager
.
TextLength
;
}
int
nLineIndex
=
c
.
TextManager
.
GetLineIndexFromCharIndex
(
nIndex
)
;
var
line
=
c
.
TextManager
[
nLineIndex
]
;
c
.
IGraphemeSplitter
.
Each
(
line
.
RawString
,
nIndex
-
line
.
IndexOfFirstChar
,
(
str
,
nStart
,
nLen
)
=>
{
nIndex
+=
nLen
;
return
false
;
}
)
;
return
nIndex
;
}
//private FindInfo FindRightChar(int nIndex) {
// //TODO: add location for return;
// var c = m_core;
// if (nIndex >= c.TextManager.TextLength) {
// return FindInfo.Empty;
// }
// int nLineIndex = c.TextManager.GetLineIndexFromCharIndex(nIndex);
// var line = c.TextManager[nLineIndex];
// c.IGraphemeSplitter.Each(line.RawString, nIndex - line.IndexOfFirstChar, (str, nStart, nLen) => {
// nIndex += nLen;
// return false;
// });
// return new FindInfo() {
// Find = true,
// Line = line,
// IndexOfCharInLine = nIndex - line.IndexOfFirstChar,
// IndexOfLine = nLineIndex,
// };
//}
public
int
FindLeftIndex
(
int
nIndex
)
{
var
c
=
m_core
;
if
(
nIndex
<=
1
)
return
0
;
int
nLineIndex
=
c
.
TextManager
.
GetLineIndexFromCharIndex
(
nIndex
)
;
TextLine
line
=
c
.
TextManager
[
nLineIndex
]
;
if
(
nIndex
==
line
.
IndexOfFirstChar
)
{
line
=
c
.
TextManager
[
--
nLineIndex
]
;
if
(
line
.
RawString
.
Length
>
1
&&
line
.
RawString
[
line
.
RawString
.
Length
-
2
]
==
'
\r
'
)
{
nIndex
-=
2
;
}
else
{
nIndex
-=
1
;
}
}
else
{
int
nIndexRet
=
line
.
IndexOfFirstChar
;
c
.
IGraphemeSplitter
.
Each
(
line
.
RawString
,
(
str
,
nStart
,
nLen
)
=>
{
if
(
nIndexRet
+
nLen
>=
nIndex
)
{
return
false
;
}
nIndexRet
+=
nLen
;
return
true
;
}
)
;
nIndex
=
nIndexRet
;
}
return
nIndex
;
}
//private FindInfo FindLeftChar(int nIndex) {
// //TODO: add location for return;
// var c = m_core;
// if (nIndex <= 1) return new FindInfo() {
// Find = true,
// Line = c.TextManager[0]
// };
// int nLineIndex = c.TextManager.GetLineIndexFromCharIndex(nIndex);
// TextLine line = c.TextManager[nLineIndex];
// if (nIndex == line.IndexOfFirstChar) {
// line = c.TextManager[--nLineIndex];
// if (line.RawString.Length > 1 && line.RawString[line.RawString.Length - 2] == '\r') {
// nIndex -= 2;
// } else {
// nIndex -= 1;
// }
// } else {
// int nIndexRet = line.IndexOfFirstChar;
// c.IGraphemeSplitter.Each(line.RawString, (str, nStart, nLen) => {
// if (nIndexRet + nLen >= nIndex) {
// return false;
// }
// nIndexRet += nLen;
// return true;
// });
// nIndex = nIndexRet;
// }
// return new FindInfo() {
// Find = true,
// Line = line,
// IndexOfCharInLine = nIndex - line.IndexOfFirstChar,
// IndexOfLine = nLineIndex
// };
//}
}
}
Back
|
FazBrowse Home
|
New Git URL