Custom Auto Edit policy (auto Edit strategy)
An important feature of the JFace Text Framework is the automatic editing strategy, which allows the user to edit the input content (accurately, the upcoming document modification ^_^), and then transparently put the user's changes into effect (i.e. Apply to the current document). In this section, we will develop an automatic editing strategy based on the previous two sections on the TLD Content model.
"JFace Text Framework Automatic editing Strategy principle Introduction"
"JDT Java Source Editor auto edit Policy Demo"
Each of our developers using the Eclipse JDT for Java programming will be impressed by the automatic editing strategy for the Java source Editor in Jdt, which is a great convenience to coders. Examples are as follows:
As shown in the figure above, we are writing a new function, the black vertical line "|" in the figure Where the cursor is, when we press the ENTER key, the effect changes as follows:
As shown in the figure above, when we enter the ENTER key, the JDT Java Source Editor automatically corrects the content (text) and location (offset): The original input should be "\ r \ n", JDT the Java source Editor to automatically help us to correct the "\r\n\t\t\r\n\t} According to the "\ r \ n" content, the cursor position should be positioned at the beginning of Line 28, and the JDT Java Source Editor will automatically help us to correct the distance of two "T" from 28 lines.
"Automatic editing processes and primary roles"
The following illustration shows the automatic editing process:
1, user edit, keyboard events
2, according to the keyboard events, analysis of event information, assembled into a data structure named Documentcommand, which contains the user's input (text), cursor position (offset) and other information, for example, the above JDT example of the user's input is "\ r \ n ”。 This step jface Text framework to help users solve.
3, call the automatic editing strategy, corresponding to the Documentcommand data for customization, for example, JDT Java Source Editor's automatic editing policy to correct the input content to "\r\n\t\t\r\n\t}". The user is responsible for the JDT Java Source Editor working here, providing its own iautoeditstrategy ^_^