Post by (X) on Oct 22, 2023 23:06:59 GMT 1
This GLL will toggle the selected text (even multiple lines) from lower to upper and vice-versa. I ran into a tricky situation when multiple lines were selected but I found a way around it.
'###############################################################################
'
' DISCLAIMER: THIS CODE IS OFFERED AS IS FOR EDUCATIONAL PURPOSES.
' YOU ARE FREE TO USE, COPY AND DISTRIBUTE.
' THE USE OF THIS CODE IS AT YOUR OWN RISK.
' I ACCEPT NO LIABILITY NOR MAKE ANY CLAIM OF
' CORRECTNESS OR SUITABILITY IN PART OR IN WHOLE.
'
'###################################################################
'
' FILENAME GFA_EX_A__TOGGLE_SELECTED_CASE.G32
'
' DESCRIPTION Shift-Ctrl-A combo calls: GFA_EX_A which alternately converts
' the selected/highlited text to UPPER or lower case.
'
' AUTHOR (X)
' EMAIL xman.gb32@gmail.com
' WEBSITE https://gb32.proboards.com/
' STARTED 2022-09-22
' UPDATED 2023-10-22 Added multiline selection fixes
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub GFA_EX_A
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' /!\ CAUTION
' Every change made to: Gfa_Line or Gfa_Col
' automatically resets: Gfa_SelLine and Gfa_SelCol
' to the value in: Gfa_Line and Gfa_Col.
' Sooooo!!! Do your Gfa_Line and Gfa_Col settings THEN Gfa_SelLine and
' Gfa_SelCol!
'
If Gfa_IsSelection
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SHIFT-CTRL-A : Toggles selected text to upper or lower case depending on the
' existing case of the selected text...
'
Local BegLine% = Gfa_SelLine
Local BegCol% = Gfa_SelCol
Local EndLine% = Gfa_Line
Local EndCol% = Gfa_Col
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Just to get a consistent substitution we'll check if the TOP-LEFT and
' BOT-RIGHT selection beg's and end's go top to bottom, Left to Right.
'
If (BegLine > EndLine)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Swap the
'
Swap BegLine, EndLine
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If we needed to swap the Beg & End lines then we must swap the Beg & End cols
' too.
'
Swap BegCol, EndCol
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If we are on the same line, make sure the beg column is smaller than end column
'
ElseIf (BegLine == EndLine)
If (BegCol > EndCol) Swap BegCol, EndCol
EndIf
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Lets try to reselect the same range that was selected before but this time
' in ascending order of line and left to right.
'
Gfa_Up
Gfa_Line = EndLine
Gfa_Col = EndCol
Gfa_SelLine = BegLine
Gfa_SelCol = BegCol
Dim Sel_s$ = Gfa_Selection
Dim Low_s$ = Lower(Sel_s$)
Dim Upr_s$ = Upper(Sel_s$)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Before performing the insert, detect if the last line is selected to the end.
' Why?
' We might have to insert a CRLF if removed by the insert operation. I know! WTF?
' I have noticed that if I select multiple lines and the last one is selected
' all the way to the end, then, when the insertion is done, the following line
' jumps up to the end of the inserted text. So, i need a way to detect if the
' last line selected is the full line length so I can insert an additional CRLF.
'
Dim InsertCrLF? = False
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If the selection spans more than 1 line...
'
If (EndLine > BegLine)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Select the last line to the end in order to know its max length...
'
Gfa_Line = EndLine
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If we specify a very large column position for Gfa_Col, it is automatically
' adjusted to the actual line length...
'
Gfa_Col = _maxInt
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Set the Beginning of the column selection...
'
Gfa_SelCol = 0
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Get the line length in chrs...
'
Dim LastLineLen% = Len(Gfa_Selection)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If the selected text goes to the end of the last line the line lenght and
' the originally selected end column should match...
'
If (LastLineLen == EndCol)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If so, set the insert carriage return & line feed flag to True.
'
InsertCrLF? = True
EndIf
EndIf
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Re-select the original selection...
'
Gfa_Line = EndLine
Gfa_Col = EndCol
Gfa_SelLine = BegLine
Gfa_SelCol = BegCol
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Insert - replace the selected text - with the upper or lower case version
' depending on the content of the selected text. ( with a CRLF if needed.)
'
If (Low_s$ == Sel_s$)
Gfa_Insert Upr_s$
Else
Gfa_Insert Low_s$
EndIf
If InsertCrLF?
Gfa_Insert #13#10
EndIf
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Re-select the original selection...
'
Gfa_Up
Gfa_Line = EndLine
Gfa_Col = EndCol
Gfa_SelLine = BegLine
Gfa_SelCol = BegCol
EndIf
EndSub