TemplateCompletion not work in autocompletion 2.5.1

General Discussion on RSyntaxTextArea.

Moderator: robert

TemplateCompletion not work in autocompletion 2.5.1

Postby vsisko » Fri Jan 31, 2014 10:23 am

Hello. When I try to use TemplateCompletion it not insert text by template and clear input start of text.

Creation of text area:

java code:

package org.fife.ui.autocomplete;

import java.awt.*;
import javax.swing.*;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rtextarea.RTextScrollPane;

public class AutoCompleteDemo extends JFrame {
private String NL = System.getProperty("line.separator");

public AutoCompleteDemo() {
JPanel contentPane = new JPanel(new BorderLayout());
RSyntaxTextArea res = new RSyntaxTextArea();
res.setSyntaxEditingStyle("text/xml");
AutoCompletion ac = new AutoCompletion(createCompletionProvider());
ac.install(res);
contentPane.add(new RTextScrollPane(res));
setContentPane(contentPane);
setTitle("AutoComplete Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setSize(400, 300);
setLocationRelativeTo(null);
}

private CompletionProvider createCompletionProvider() {
DefaultCompletionProvider provider = new DefaultCompletionProvider();

provider.addCompletion(new TemplateCompletion(provider, "bean", "bean - Bean node with class attribute",
"<bean class=\"${class}\">" + NL + "\t${cursor}" + NL + "</bean>"));

provider.addCompletion(new TemplateCompletion(provider, "bean", "Bean node with id and class attributes",
"<bean id=\"${id}\" class=\"${class}\">" + NL + "\t${cursor}" + NL + "</bean>"));

provider.addCompletion(new TemplateCompletion(provider, "property", "Property node with name attribute",
"<property name=\"${name}\">" + NL + "\t${cursor}" + NL + "</property>"));

provider.addCompletion(new TemplateCompletion(provider, "property", "Property node with name and value attributes",
"<property name=\"${name}\" value=\"${value}\"/>"));

return provider;
}

public static void main(String[] args) {
new AutoCompleteDemo().setVisible(true);
}
}


For example:
Input property word. Press “Ctrl+Space”, select one of possible variants for
vsisko
 
Posts: 2
Joined: Fri Jan 31, 2014 8:41 am

Re: TemplateCompletion not work in autocompletion 2.5.1

Postby robert » Sun Feb 02, 2014 4:05 pm

There are a couple of issues at play here.

First, you need to call setParameterAssistanceEnabled(true) on your AutoCompletion for it to be aware of parameterized completions:

java code:

AutoCompletion ac = new AutoCompletion(createCompletionProvider());
ac.setParameterAssistanceEnabled(true);


This will fix your issue, for the most part. The only kink is that template completions don't work when the caret is at offset 0 (see the bug report here). So when trying this out, just have the caret somewhere past offset 0 :)

Finally, just as a side note, you shouldn't use the OS-specific newline character in Swing JTextComponents. Always just use "\n". Using "\r\n" on Windows may cause caret navigation issues, as Swing expects newlines to always be 1 character in its in-memory representation of the text.

Hope that helps!
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron