Page 1 of 1

Text selet/insert box?

Posted: Wed Apr 21, 2021 11:17 pm
by wmaclean
Hello,
What is the name of a pop-up box like the one used for inserting tags? This one:
image.png
image.png (11.16 KiB) Viewed 1570 times
Does it have an API?
Can it stay open while a user is typing?
Can it have an event listener, to keep track of what they are typing?
Can it talk so a REST service, which would be used to populate it with text they might choose to insert?

Thank you,
Will

Re: Text selet/insert box?

Posted: Thu Apr 22, 2021 2:48 pm
by alex_jitianu
Hello,

This is the content completion window and it's not accessible though the API. If you can tell me more about what you are after, the use case, then perhaps I can offer an alternative solution.

Best regards,
Alex

Re: Text selet/insert box?

Posted: Fri Apr 23, 2021 5:23 pm
by wmaclean
Hi Alex,
What we are hoping to do is something like this.

We already have a machine learning model that suggests words based on other words exposed through a REST API. We send it some words, and it returns some suggestions for the next word.

We would like to have a text select box that floats over the editing area while the writer types - and while the writer types, that box keeps track of what the writer is typing, sends that information to the REST API, then displays the text results that are returned, which the writer can then click on to insert into the text, if they see the word they need.

A simple example might look something like this:
image.png
image.png (14.49 KiB) Viewed 1545 times
The box would be opened or closed based on a selection in the right-click menu.

Is there an oXygen API that would support that behavior?

Thank you for any ideas you might share,
Will

Re: Text selet/insert box?

Posted: Mon Apr 26, 2021 4:46 pm
by alex_jitianu
Hi,

It can be done through our Java-based API as a plugin. Here are a few ideas:
1. You need a Workspace Access plugin. A good starting point is available on GitHub.
2. I think it would be easier to present these proposals in a custom side view
3. We have API to listen for editing events. The GitHub sample project demonstrates how to set a ro.sync.exml.workspace.api.listeners.WSEditorChangeListener. In its editorOpened() callback, you can get the text typed so far by the user in fashion similar to this.

Code: Select all

@Override
public void editorOpened(URL editorLocation) {
  
  WSEditor editorAccess = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
  editorAccess.addEditorListener(new WSEditorListener() {
    @Override
    public void editorPageChanged() {
      install(editorAccess);
    }
  });
  install(editorAccess);
}

private void install(WSEditor wsEditor) {
  if (wsEditor.getCurrentPageID() == EditorPageConstants.PAGE_AUTHOR) {
    WSAuthorEditorPage authorPage = (WSAuthorEditorPage) wsEditor.getCurrentPage();
    
    AuthorDocumentController documentController = authorPage.getAuthorAccess().getDocumentController();
    documentController.addAuthorListener(new AuthorListenerAdapter() {
      public void contentInserted(DocumentContentInsertedEvent e) {
        String insertedText = e.getInsertedText();
        int offset = e.getOffset();
        
        try {
          AuthorNode nodeAtOffset = documentController.getNodeAtOffset(offset);
          
          TextContentIterator textIterator = documentController.getTextContentIterator(nodeAtOffset.getStartOffset(), offset + insertedText.length());
          while (textIterator.hasNext()) {
            TextContext next = textIterator.next();
          }
        } catch (BadLocationException e1) {
          e1.printStackTrace();
        }
      }
    });
  }
}
4. You can add an action in the contextual menu. This action will activate/deactivate the entire functionality. The sample project from GitHub has a sample code that contributes action into the contextual menu. The method of interest is customizePopupMenu()

When you start working on it, please let me know and perhaps I can give more help. For example you should use a coalescing mechanism to avoid doing this processing in excess.

Best regards,
Alex

Re: Text selet/insert box?

Posted: Tue Apr 27, 2021 5:15 pm
by wmaclean
Hi Alex,
Thank you very much for such excellent ideas!

We already have a Workspace plugin, so that's one requirement met.

I will study what you've sent for custom side view and WSEditorChangeListener, and see what we can do.

I really appreciate your input, and will come back here with questions as we start to work on this.

Have a good one,
Will