1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-06-29 10:30:36 +00:00

Unifies code to delete selection and insert text.

This commit is contained in:
FellippeHeitor 2021-01-21 01:18:40 -03:00
parent ea1b0b1a51
commit a0744ef32c

View file

@ -3377,7 +3377,7 @@ FUNCTION ide2 (ignore)
IF (KB = KEY_DELETE OR KB = 8) AND ideselect = 1 THEN 'delete selection IF (KB = KEY_DELETE OR KB = 8) AND ideselect = 1 THEN 'delete selection
IF ideselecty1 <> idecy OR ideselectx1 <> idecx THEN IF ideselecty1 <> idecy OR ideselectx1 <> idecx THEN
idechangemade = 1 idechangemade = 1
GOSUB delselect delselect
GOTO specialchar GOTO specialchar
ELSE ELSE
ideselect = 0 ideselect = 0
@ -3391,10 +3391,10 @@ FUNCTION ide2 (ignore)
clip$ = _CLIPBOARD$ 'read clipboard clip$ = _CLIPBOARD$ 'read clipboard
IF LEN(clip$) THEN IF LEN(clip$) THEN
IF ideselect THEN GOSUB delselect
IF INSTR(clip$, CHR$(13)) OR INSTR(clip$, CHR$(10)) THEN IF INSTR(clip$, CHR$(13)) OR INSTR(clip$, CHR$(10)) THEN
'full lines paste 'full lines paste
IF ideselect THEN delselect
idelayoutallow = 2 idelayoutallow = 2
a$ = clip$ a$ = clip$
@ -3433,17 +3433,8 @@ FUNCTION ide2 (ignore)
END IF END IF
END IF END IF
ELSE ELSE
'insert single line paste 'insert single line paste
a$ = idegetline(idecy) insertAtCursor clip$
IF LEN(a$) < idecx - 1 THEN a$ = a$ + SPACE$(idecx - 1 - LEN(a$))
a$ = LEFT$(a$, idecx - 1) + clip$ + RIGHT$(a$, LEN(a$) - idecx + 1)
idesetline idecy, converttabs$(a$)
IF PasteCursorAtEnd THEN
'Place the cursor at the end of the pasted content:
idecx = idecx + LEN(clip$)
END IF
END IF END IF
idechangemade = 1 idechangemade = 1
@ -3455,7 +3446,7 @@ FUNCTION ide2 (ignore)
copy2clip: copy2clip:
clip$ = getSelectedText$(-1) clip$ = getSelectedText$(-1)
IF clip$ <> "" THEN _CLIPBOARD$ = clip$ IF clip$ <> "" THEN _CLIPBOARD$ = clip$
IF (K$ = CHR$(0) + "S") OR (KSHIFT AND KB = KEY_DELETE) OR (KCONTROL AND UCASE$(K$) = "X") THEN GOSUB delselect IF (K$ = CHR$(0) + "S") OR (KSHIFT AND KB = KEY_DELETE) OR (KCONTROL AND UCASE$(K$) = "X") THEN delselect
GOTO specialchar GOTO specialchar
END IF END IF
@ -3649,45 +3640,6 @@ FUNCTION ide2 (ignore)
END IF END IF
RETURN RETURN
delselect:
sy1 = ideselecty1
sy2 = idecy
IF sy1 > sy2 THEN SWAP sy1, sy2
sx1 = ideselectx1
sx2 = idecx
IF sx1 > sx2 THEN SWAP sx1, sx2
nolastlinedel = 0
IF sy1 <> sy2 AND idecx = 1 AND idecy > sy1 THEN sy2 = sy2 - 1: nolastlinedel = 1 'ignore last line of multi-line select?
FOR y = sy2 TO sy1 STEP -1
IF sy1 = sy2 AND nolastlinedel = 0 THEN 'single line select
a$ = idegetline(y)
a2$ = ""
IF sx1 <= LEN(a$) THEN a2$ = LEFT$(a$, sx1 - 1) ELSE a2$ = a$
IF sx2 <= LEN(a$) THEN a2$ = a2$ + RIGHT$(a$, LEN(a$) - sx2 + 1)
idesetline y, a2$
ELSE 'multiline select
IF iden = 1 AND y = 1 THEN idesetline y, "" ELSE idedelline y
END IF
NEXT
idecx = sx1: IF sy1 <> sy2 OR nolastlinedel = 1 THEN idecx = 1
idecy = sy1
ideselect = 0
RETURN
skipgosubs: skipgosubs:
IF K$ = CHR$(13) THEN IF K$ = CHR$(13) THEN
@ -3718,23 +3670,7 @@ FUNCTION ide2 (ignore)
retval$ = idergbmixer$(-1) retval$ = idergbmixer$(-1)
END IF END IF
END IF END IF
IF LEN(retval$) THEN IF LEN(retval$) THEN insertAtCursor retval$
tempk$ = retval$
'insert
IF ideselect THEN GOSUB delselect
a$ = idegetline(idecy)
IF LEN(a$) < idecx - 1 THEN a$ = a$ + SPACE$(idecx - 1 - LEN(a$))
a$ = LEFT$(a$, idecx - 1) + tempk$ + RIGHT$(a$, LEN(a$) - idecx + 1)
idesetline idecy, a$
IF PasteCursorAtEnd THEN
'Place the cursor at the end of the inserted content:
idecx = idecx + LEN(tempk$)
END IF
idechangemade = 1
END IF
GOTO specialchar GOTO specialchar
ELSE ELSE
ideselect = 0 ideselect = 0
@ -4058,7 +3994,7 @@ FUNCTION ide2 (ignore)
IF KALT AND NOT KCTRL AND NOT AltSpecial THEN GOTO specialchar IF KALT AND NOT KCTRL AND NOT AltSpecial THEN GOTO specialchar
'standard character 'standard character
IF ideselect THEN GOSUB delselect IF ideselect THEN delselect
idechangemade = 1 idechangemade = 1
'undocombos 'undocombos
@ -4786,23 +4722,7 @@ FUNCTION ide2 (ignore)
HideBracketHighlight HideBracketHighlight
keywordHighlight = oldkeywordHighlight keywordHighlight = oldkeywordHighlight
retval$ = idergbmixer$(-1) 'retval is ignored retval$ = idergbmixer$(-1) 'retval is ignored
IF LEN(retval$) THEN IF LEN(retval$) THEN insertAtCursor retval$
tempk$ = retval$
'insert
IF ideselect THEN GOSUB delselect
a$ = idegetline(idecy)
IF LEN(a$) < idecx - 1 THEN a$ = a$ + SPACE$(idecx - 1 - LEN(a$))
a$ = LEFT$(a$, idecx - 1) + tempk$ + RIGHT$(a$, LEN(a$) - idecx + 1)
idesetline idecy, a$
IF PasteCursorAtEnd THEN
'Place the cursor at the end of the inserted content:
idecx = idecx + LEN(tempk$)
END IF
idechangemade = 1
END IF
PCOPY 3, 0: SCREEN , , 3, 0: idewait4mous: idewait4alt PCOPY 3, 0: SCREEN , , 3, 0: idewait4mous: idewait4alt
GOTO ideloop GOTO ideloop
END IF END IF
@ -5019,23 +4939,7 @@ FUNCTION ide2 (ignore)
PCOPY 2, 0 PCOPY 2, 0
DO DO
retval$ = ideASCIIbox$(relaunch) retval$ = ideASCIIbox$(relaunch)
IF LEN(retval$) THEN IF LEN(retval$) THEN insertAtCursor retval$
tempk$ = retval$
'insert
IF ideselect THEN GOSUB delselect
a$ = idegetline(idecy)
IF LEN(a$) < idecx - 1 THEN a$ = a$ + SPACE$(idecx - 1 - LEN(a$))
a$ = LEFT$(a$, idecx - 1) + tempk$ + RIGHT$(a$, LEN(a$) - idecx + 1)
idesetline idecy, a$
IF PasteCursorAtEnd THEN
'Place the cursor at the end of the inserted content:
idecx = idecx + LEN(tempk$)
END IF
idechangemade = 1
END IF
PCOPY 3, 0: SCREEN , , 3, 0: idewait4mous: idewait4alt PCOPY 3, 0: SCREEN , , 3, 0: idewait4mous: idewait4alt
GOSUB redrawItAll GOSUB redrawItAll
ideshowtext ideshowtext
@ -5081,18 +4985,8 @@ FUNCTION ide2 (ignore)
tempk$ = LTRIM$(tempk$) tempk$ = LTRIM$(tempk$)
'insert 'insert
IF ideselect THEN GOSUB delselect insertAtCursor tempk$
a$ = idegetline(idecy)
IF LEN(a$) < idecx - 1 THEN a$ = a$ + SPACE$(idecx - 1 - LEN(a$))
a$ = LEFT$(a$, idecx - 1) + tempk$ + RIGHT$(a$, LEN(a$) - idecx + 1)
idesetline idecy, a$
IF PasteCursorAtEnd THEN
'Place the cursor at the end of the inserted content:
idecx = idecx + LEN(tempk$)
END IF
idechangemade = 1
bypassCtrlK: bypassCtrlK:
dummy = DarkenFGBG(0) dummy = DarkenFGBG(0)
PCOPY 3, 0: SCREEN , , 3, 0: idewait4mous: idewait4alt PCOPY 3, 0: SCREEN , , 3, 0: idewait4mous: idewait4alt
@ -5234,21 +5128,7 @@ FUNCTION ide2 (ignore)
LOOP LOOP
IF mathEvalError%% = 0 AND result = 1 THEN IF mathEvalError%% = 0 AND result = 1 THEN
tempk$ = mathMsg$ insertAtCursor mathMsg$
'insert
IF ideselect THEN GOSUB delselect
a$ = idegetline(idecy)
IF LEN(a$) < idecx - 1 THEN a$ = a$ + SPACE$(idecx - 1 - LEN(a$))
a$ = LEFT$(a$, idecx - 1) + tempk$ + RIGHT$(a$, LEN(a$) - idecx + 1)
idesetline idecy, a$
IF PasteCursorAtEnd THEN
'Place the cursor at the end of the inserted content:
idecx = idecx + LEN(tempk$)
END IF
idechangemade = 1
END IF END IF
PCOPY 3, 0: SCREEN , , 3, 0 PCOPY 3, 0: SCREEN , , 3, 0
GOTO ideloop GOTO ideloop
@ -5565,7 +5445,7 @@ FUNCTION ide2 (ignore)
PCOPY 3, 0: SCREEN , , 3, 0: idewait4mous: idewait4alt PCOPY 3, 0: SCREEN , , 3, 0: idewait4mous: idewait4alt
IF IdeSystem = 1 AND ideselect = 1 THEN IF IdeSystem = 1 AND ideselect = 1 THEN
idechangemade = 1 idechangemade = 1
GOSUB delselect delselect
ELSEIF IdeSystem = 2 THEN ELSEIF IdeSystem = 2 THEN
GOTO deleteSelectionSearchField GOTO deleteSelectionSearchField
END IF END IF
@ -14810,4 +14690,48 @@ FUNCTION getSelectedText$(multiline AS _BYTE)
END IF END IF
END FUNCTION END FUNCTION
SUB delselect
sy1 = ideselecty1
sy2 = idecy
IF sy1 > sy2 THEN SWAP sy1, sy2
sx1 = ideselectx1
sx2 = idecx
IF sx1 > sx2 THEN SWAP sx1, sx2
nolastlinedel = 0
IF sy1 <> sy2 AND idecx = 1 AND idecy > sy1 THEN sy2 = sy2 - 1: nolastlinedel = 1 'ignore last line of multi-line select?
FOR y = sy2 TO sy1 STEP -1
IF sy1 = sy2 AND nolastlinedel = 0 THEN 'single line select
a$ = idegetline(y)
a2$ = ""
IF sx1 <= LEN(a$) THEN a2$ = LEFT$(a$, sx1 - 1) ELSE a2$ = a$
IF sx2 <= LEN(a$) THEN a2$ = a2$ + RIGHT$(a$, LEN(a$) - sx2 + 1)
idesetline y, a2$
ELSE 'multiline select
IF iden = 1 AND y = 1 THEN idesetline y, "" ELSE idedelline y
END IF
NEXT
idecx = sx1: IF sy1 <> sy2 OR nolastlinedel = 1 THEN idecx = 1
idecy = sy1
ideselect = 0
END SUB
SUB insertAtCursor (tempk$)
'insert
IF ideselect THEN delselect
a$ = idegetline(idecy)
IF LEN(a$) < idecx - 1 THEN a$ = a$ + SPACE$(idecx - 1 - LEN(a$))
a$ = LEFT$(a$, idecx - 1) + tempk$ + RIGHT$(a$, LEN(a$) - idecx + 1)
idesetline idecy, converttabs$(a$)
IF PasteCursorAtEnd THEN
'Place the cursor at the end of the inserted content:
idecx = idecx + LEN(tempk$)
END IF
idechangemade = 1
END SUB
'$INCLUDE:'wiki\wiki_methods.bas' '$INCLUDE:'wiki\wiki_methods.bas'