I liked the way Dabblet does autoindenting (entering a new line copies the whitespace from the beginning of the current line, so you keep the same level of indentation). So I added an option to bililiteRange(element).text()
to do that. Now bililiteRange(element).text('text to insert', select, true)
with true
passed as the last option will autoindent. My Prism editor now has a check box to implement that.
The code to do this is in the bililiteRange utilities, not the original code.
I also added two more bililiteRange plugins:
bililiteRange(element).indent(tabs)
- Prepends the string
tabs
to each line that contains part of the range. ThusbililiteRange(element).bounds('selection').indent('\t')
to indent by one tab (and if you want spaces, use those instead; I won't get into Holy Wars). bililiteRange(element).unindent(n, tabSize)
- Removes
n
tab characters or sequences oftabSize
spaces from the start of each line.
And, inspired by jQuery data
, added a bililiteRange(element).data()
that returns an object tied to element
that can be used to store any data on that element (not the bililiteRange) without memory leaks. Thus bililiteRange(element).data().tabSize = 4
can be used in future calls: assert(bililiteRange(element).data().tabSize == 4)
. In fact, unindent
above does exactly that if tabSize
is not passed in.
Leave a Reply