Well that didn't work...
Jeanne A. E. DeVoto
revolution at jaedworks.com
Tue Jun 21 16:53:58 EDT 2005
At 10:38 PM -0700 6/20/2005, Todd Geist wrote:
>Hello,
>
>I have been trying to figure out how to create a little simple text
>editor. Basically I want to add two features to a regular scrolling
>field.
>
>Feature 1
>
> Pressing tab while the insertion point is on a line of text
>needs to INDENT the line
> pressing shift_tab needs to OUTDENT it.
This used to be in the docs, but I think it's been taken out:
on tabKey
if the selectedText is empty then pass tabKey
-- there's an insertion point, but no selection,
-- so let tab key operate normally. Otherwise...
put the selectedLines into savedSelectedLines -- save for later
put word 2 of the selectedLines into firstLine
if word 3 of the selectedLines is "to" then
-- multiple lines are selected
put word 4 of the selectedLines into lastLine
else -- single line is selected
put firstLine into lastLine
end if
if the shiftKey is down then -- shift left - remove a tab:
repeat with thisLine = firstLine to lastLine
if char 1 of line thisLine \
of (the text of the selectedField) is tab
then delete char 1 of line thisLine \
of the selectedField -- remove leading tab
end repeat
else -- shift key not down, so shift right - add a tab:
repeat with thisLine = firstLine to lastLine
-- add a leading tab to each line in the selection
put tab before line thisLine of the selectedField
end repeat
end if
select savedSelectedLines -- (re)select all affected lines
end tabKey
>Feature 2
>
> A new Line created by pressing "return" needs to line up with
>the previous line
This should work:
on returnInField
put return & leadingWhiteSpace(the value of the selectedLine) \
into the selection
end returnInField
function leadingWhiteSpace theText
local myWhiteSpace
repeat for each char thisChar in theText
if thisChar is in (tab & space)
then put thisChar after myWhiteSpace
else exit repeat
end repeat
return myWhiteSpace
end leadingWhiteSpace
--
jeanne a. e. devoto ~ revolution at jaedworks.com
http://www.jaedworks.com
More information about the use-livecode
mailing list