Fresh IDE . Check-in [22f4724e5a]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Deleting characters.
Timelines: family | ancestors | descendants | both | NoCanvasGUI
Files: files | file ages | folders
SHA1:22f4724e5a687f2dec359844ec4a7f63cdbd930e
User & Date: johnfound 2019-04-29 07:13:56
Context
2019-04-30
22:05
Work on the syntax highlighter. Fixed the text rendering with a syntax highlight. check-in: 765802a720 user: johnfound tags: NoCanvasGUI
2019-04-29
07:13
Deleting characters. check-in: 22f4724e5a user: johnfound tags: NoCanvasGUI
2019-04-28
14:31
Fixed selection rectangles list creation. Fixed selection delete method. Code cleanup. check-in: b233c364d5 user: johnfound tags: NoCanvasGUI
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/data/buffergap.asm.

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66



67
68
69
70
71
72
73
..
76
77
78
79
80
81
82










83
84
85
86
87
88
89
...
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
...
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
        xor     edx, edx
        mov     ebx, [.index]

.loop:
        dec     ebx
        js      .finish

        cmp     edx, [esi+TText.Length]
        cmova   edx, [esi+TText.Length]
        jae     .finish

        mov     eax, [esi+TText.GapBegin]
        cmp     edx, eax
        cmovae  eax, [esi+TText.GapEnd]
        sub     eax, [esi+TText.GapBegin]
        add     eax, edx




        movzx   eax, byte [esi+eax]

                                ; compute the length of the UTF-8 character by its first byte (version without branches) Is it fast?
        not     al              ; utf-8 starts with one of: 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx, 111110xx, 1111110x
        bsr     eax, eax        ; eax =                 7,  5,  4,  3,  2,  1
        sub     eax, 7          ; eax =                 0, -2, -3, -4, -5, -6
................................................................................
        sbb     eax, -2         ; eax = edx + 2 - CF = +1, +2, +3, +4, +5, +6

        add     edx, eax
        jmp     .loop

.finish:
        mov     [esp+4*regEAX], edx










        popad
        return
endp




................................................................................
        mov     ebx, [.pText]

        cmp     eax, [ebx+TText.GapBegin]
        jb      @f
        add     eax, [ebx+TText.GapEnd]
        sub     eax, [ebx+TText.GapBegin]
@@:
        cmp     eax, [ebx+TText.TextLen]
        cmova   eax, [ebx+TText.TextLen]
        pop     ebx
        return
endp


macro pos2ofs  pos, text {
local ..skip
................................................................................

  if pos eqtype eax & text eqtype eax
    cmp    pos, [text+TText.GapBegin]
    jb     ..skip
    add    pos, [text+TText.GapEnd]
    sub    pos, [text+TText.GapBegin]
..skip:
;    cmp    pos, [text+TText.Length]    ; ?????????
;    cmova  pos, [text+TText.Length]    ; ?????????
  else
    error "Error! Arguments must be registers!"
    err
  end if
}


................................................................................




; Deletes one UTF-8 character at the current gap position.
; esi - pointer to TText

proc TextDelChar
begin
        push    eax

        mov     eax, [esi+TText.GapStart]
        add     eax, [esi+TText.GapLen]

        stdcall DecodeUtf8, [esi+eax]
        add     [esi+TText.GapLen], edx

.len_ok:
        pop     eax
        return
endp




; Inserts a string in the TText structure
; which can be pointer to NULL terminated string or
; string handle.







<
<
<
<





>
>
>







 







>
>
>
>
>
>
>
>
>
>







 







|
|







 







|
|







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|







51
52
53
54
55
56
57




58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
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
...
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
        xor     edx, edx
        mov     ebx, [.index]

.loop:
        dec     ebx
        js      .finish





        mov     eax, [esi+TText.GapBegin]
        cmp     edx, eax
        cmovae  eax, [esi+TText.GapEnd]
        sub     eax, [esi+TText.GapBegin]
        add     eax, edx

        cmp     eax, [esi+TText.Length]
        jae     .error

        movzx   eax, byte [esi+eax]

                                ; compute the length of the UTF-8 character by its first byte (version without branches) Is it fast?
        not     al              ; utf-8 starts with one of: 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx, 111110xx, 1111110x
        bsr     eax, eax        ; eax =                 7,  5,  4,  3,  2,  1
        sub     eax, 7          ; eax =                 0, -2, -3, -4, -5, -6
................................................................................
        sbb     eax, -2         ; eax = edx + 2 - CF = +1, +2, +3, +4, +5, +6

        add     edx, eax
        jmp     .loop

.finish:
        mov     [esp+4*regEAX], edx
        clc
        popad
        return

.error:
        mov     eax, [esi+TText.Length]
        sub     eax, [esi+TText.GapEnd]
        add     eax, [esi+TText.GapBegin]
        mov     [esp+4*regEAX], eax
        stc
        popad
        return
endp




................................................................................
        mov     ebx, [.pText]

        cmp     eax, [ebx+TText.GapBegin]
        jb      @f
        add     eax, [ebx+TText.GapEnd]
        sub     eax, [ebx+TText.GapBegin]
@@:
        cmp     eax, [ebx+TText.Length]
        cmova   eax, [ebx+TText.Length]
        pop     ebx
        return
endp


macro pos2ofs  pos, text {
local ..skip
................................................................................

  if pos eqtype eax & text eqtype eax
    cmp    pos, [text+TText.GapBegin]
    jb     ..skip
    add    pos, [text+TText.GapEnd]
    sub    pos, [text+TText.GapBegin]
..skip:
    cmp    pos, [text+TText.Length]    ; ?????????
    cmova  pos, [text+TText.Length]    ; ?????????
  else
    error "Error! Arguments must be registers!"
    err
  end if
}


................................................................................




; Deletes one UTF-8 character at the current gap position.
; esi - pointer to TText

;proc TextDelChar
;begin
;        push    eax
;
;        mov     eax, [esi+TText.GapStart]
;        add     eax, [esi+TText.GapLen]
;
;        stdcall DecodeUtf8, [esi+eax]
;        add     [esi+TText.GapLen], edx
;
;.len_ok:
;        pop     eax
;        return
;endp




; Inserts a string in the TText structure
; which can be pointer to NULL terminated string or
; string handle.

Changes to freshlib/gui/TAsmEdit.asm.

226
227
228
229
230
231
232

233
234
235
236
237


238
239
240
241
242
243
244
....
1140
1141
1142
1143
1144
1145
1146

1147

































1148
1149
1150
1151
1152
1153
1154
....
3320
3321
3322
3323
3324
3325
3326





























































3327
3328
3329
3330
3331
3332
3333
....
3506
3507
3508
3509
3510
3511
3512
3513

3514
3515
3516
3517
3518
3519
3520
3521


3522
3523
3524
3525
3526
3527
3528


; Text editing methods

  method .InsertNewLine, .LineNum
  method .DeleteLine, .LineNum
  method .DeleteChars, .LineNum, .From, .To

  method .JoinNextLine, .LineNum

  method .DeleteSelection
  method .InsertString, .text
  method .ReplaceSelection, .text



; OS event handlers

  method .EventFocusIn
  method .EventFocusOut

  method .EventScroll, .direction, .command, .value
................................................................................
.ins_mask_ok:
        xor     eax, edx
        set     esi, TAsmEdit:Options, eax
        jmp     .endselect

.delkey:
        exec    esi, TAsmEdit:DeleteSelection



































        exec    esi, TAsmEdit:SelChangeBegin
        exec    esi, TAsmEdit:SelStartHere
        exec    esi, TAsmEdit:SelEndHere
        exec    esi, TAsmEdit:SelChangeEnd
        jmp     .finish


................................................................................
begin
        return
endp


method TAsmEdit.DeleteChars     ;, .LineNum, .From, .To
begin





























































        return
endp


method TAsmEdit.JoinNextLine    ;, .LineNum
begin
        pushad
................................................................................
        mov     [.rect.top], eax
        mov     [.rect.right], ecx
        mov     [.rect.bottom], edx
        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect.top], [.rect.bottom]
        exec    esi, TAsmEdit:RectChanged2, 0
        exec    esi, TAsmEdit:UpdateCaretPos


.exit:
        stdcall FreeMem, [.list]
        clc
        popad
        return

.exit_empty:


        stdcall FreeMem, [.list]
        stc
        popad
        return
endp









>



<

>
>







 







>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>








>
>







226
227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244
245
246
....
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
....
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
....
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628


; Text editing methods

  method .InsertNewLine, .LineNum
  method .DeleteLine, .LineNum
  method .DeleteChars, .LineNum, .From, .To

  method .JoinNextLine, .LineNum

  method .DeleteSelection

  method .ReplaceSelection, .text

  method .InsertString, .text

; OS event handlers

  method .EventFocusIn
  method .EventFocusOut

  method .EventScroll, .direction, .command, .value
................................................................................
.ins_mask_ok:
        xor     eax, edx
        set     esi, TAsmEdit:Options, eax
        jmp     .endselect

.delkey:
        exec    esi, TAsmEdit:DeleteSelection
        jnc     .del_ok

        DebugMsg "No selection - delete the char under the caret."

        exec    esi, TAsmEdit:TextLine, [esi+TAsmEdit._caretPos.y]
        jc      .finish

        mov     ebx, eax        ; TTextLine

        OutputValue "TTextLine length = ", [ebx+TTextLine.ch_len], 16, 8
        OutputValue "_caretPos.x = ", [esi+TAsmEdit._caretPos.x], 16, 8

        mov     eax, [esi+TAsmEdit._caretPos.x]
        inc     eax
        cmp     eax, [ebx+TTextLine.ch_len]
        jbe     .del_char

        DebugMsg "Join the next line."

        exec    esi, TAsmEdit:JoinNextLine, [esi+TAsmEdit._caretPos.y]
        jmp     .del_refresh

.del_char:
        OutputValue "Delete char on line: ", [esi+TAsmEdit._caretPos.y], 10, -1
        exec    esi, TAsmEdit:DeleteChars, [esi+TAsmEdit._caretPos.y], [esi+TAsmEdit._caretPos.x], eax

.del_refresh:

        and     [esi+TAsmEdit._img_txt_valid], 0
        and     [esi+TAsmEdit._img_margin_valid], 0

        exec    esi, TAsmEdit:RectChanged2, 0
        exec    esi, TAsmEdit:UpdateCaretPos

.del_ok:
        exec    esi, TAsmEdit:SelChangeBegin
        exec    esi, TAsmEdit:SelStartHere
        exec    esi, TAsmEdit:SelEndHere
        exec    esi, TAsmEdit:SelChangeEnd
        jmp     .finish


................................................................................
begin
        return
endp


method TAsmEdit.DeleteChars     ;, .LineNum, .From, .To
begin
        pushad

        mov     esi, [.self]
        mov     edi, [esi+TAsmEdit._lines]
        mov     ebx, [.LineNum]

        shl     ebx, 2
        cmp     ebx, [edi+TText.GapBegin]
        jb      .skip
        add     ebx, [edi+TText.GapEnd]
        sub     ebx, [edi+TText.GapBegin]
.skip:
        cmp     ebx, [edi+TText.Length]
        jae     .finish

        mov     ebx, [edi+ebx]
        stdcall TextIndexToPos, ebx, [.From]
        jc      .finish

        stdcall TextMoveGap, ebx, eax
        mov     edx, [ebx+TTextLine.GapEnd]
        mov     ecx, [.From]

.loop:
        cmp     ecx, [.To]
        jae     .end_scan

        cmp     edx, [ebx+TTextLine.Length]
        cmova   edx, [ebx+TTextLine.Length]
        jae     .end_scan

        movzx   eax, byte [ebx+edx]

                                ; compute the length of the UTF-8 character by its first byte (version without branches) Is it fast?
        not     al              ; utf-8 starts with one of: 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx, 111110xx, 1111110x
        bsr     eax, eax        ; eax =                 7,  5,  4,  3,  2,  1
        sub     eax, 7          ; eax =                 0, -2, -3, -4, -5, -6
                                ; CF  =                 0,  1,  1,  1,  1,  1
        not     eax             ; eax =                -1, +1, +2, +3, +4, +5
        sbb     eax, -2         ; eax = edx + 2 - CF = +1, +2, +3, +4, +5, +6

        add     edx, eax
        inc     ecx
        jmp     .loop

.end_scan:
        mov     [ebx+TTextLine.GapEnd], edx
        sub     ecx, [.From]

        stdcall DecCount, [esi+TAsmEdit._line_widths], [ebx+TTextLine.ch_len]
        sub     [ebx+TTextLine.ch_len], ecx
        stdcall IncCount, edx, [ebx+TTextLine.ch_len]
        mov     [esi+TAsmEdit._line_widths], edx

        and     [esi+TAsmEdit._img_txt_valid], 0
        and     [esi+TAsmEdit._img_margin_valid], 0
        exec    esi, TAsmEdit:RectChanged2, 0
        exec    esi, TAsmEdit:UpdateCaretPos

.finish:
        popad
        return
endp


method TAsmEdit.JoinNextLine    ;, .LineNum
begin
        pushad
................................................................................
        mov     [.rect.top], eax
        mov     [.rect.right], ecx
        mov     [.rect.bottom], edx
        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect.top], [.rect.bottom]
        exec    esi, TAsmEdit:RectChanged2, 0
        exec    esi, TAsmEdit:ScrollToCaretX
        exec    esi, TAsmEdit:ScrollToCaretY

.exit:
        stdcall FreeMem, [.list]
        clc
        popad
        return

.exit_empty:
        DebugMsg "Exit delete selection EMPTY!"

        stdcall FreeMem, [.list]
        stc
        popad
        return
endp