From Inspired-Lua Wiki
(Redirected from D2Editor.setExpression)
Jump to navigation Jump to search

D2Editor:setExpression is a function that is part of the D2Editor Library.

This function sets the contents of a D2Editor, and is a synonym of setText.


D2Editor:setExpression(text, [cursor], [selection])
Sets the content to text, or appends it to a certain position if cursor is set. If selection is -1, no text is selected (?).


function on.construction() -- or on.create if OS 3.1
	editor = D2Editor.newRichText()

function on.charIn(char)
	currentText = editor:getExpression() -- or editor:getText()
	editor:setExpression(currentText .. char) -- or editor:setText(...)
	--Add char to the editor

function on.enterKey()
	--Add a new line

A very simple text editor (its actually more complicated, but it shows the basics).

Tips & Tricks

In order to insert some special template like MathBoxes, vectors shapes, angles etc., you have to put these in the setExpression argument :

  • \\1angle : The text rendered inside is will be displayed under the "angle" shape
  • \\1circle : Symbol for circle
  • \\1keyword :
  • \\1line : Symbol for line (parenthesis)
  • \\1lineseg : Symbol for line segment
  • \\1ray :
  • \\1rtri :
  • \\1subhead :
  • \\1subscrp : Subscript text
  • \\1supersc : Superscript text
  • \\1title :
  • \\1tri : Triangle symbol
  • \\1vector : The text rendered inside is will be displayed under the vector arrow.
  • \\1word :
  • \\0el {content} : Inserts a MathBox with the content inside it.

For example, editor:setExpression("\\1vector AB") will render as : http://i.imgur.com/aqVd8.jpg

See also

<categorytree mode=pages>D2Editor</categorytree>