Text selet/insert box?

Post here questions and problems related to oXygen frameworks/document types.
wmaclean
Posts: 41
Joined: Sat Jan 04, 2020 1:17 am

Text selet/insert box?

Post by wmaclean » Wed Apr 21, 2021 11:17 pm

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 240 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

alex_jitianu
Posts: 820
Joined: Wed Nov 16, 2005 11:11 am

Re: Text selet/insert box?

Post by alex_jitianu » Thu Apr 22, 2021 2:48 pm

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

wmaclean
Posts: 41
Joined: Sat Jan 04, 2020 1:17 am

Re: Text selet/insert box?

Post by wmaclean » Fri Apr 23, 2021 5:23 pm

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 215 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

alex_jitianu
Posts: 820
Joined: Wed Nov 16, 2005 11:11 am

Re: Text selet/insert box?

Post by alex_jitianu » Mon Apr 26, 2021 4:46 pm

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

wmaclean
Posts: 41
Joined: Sat Jan 04, 2020 1:17 am

Re: Text selet/insert box?

Post by wmaclean » Tue Apr 27, 2021 5:15 pm

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

Post Reply