I would like to add a marker in Codemirror after syntax highlighting has completed, so that I can identify certain tokens and place them there. Is there some sort of syntax highlighting completed event, and also, a way to check the tokens after that?
Don't rely on the DOM structure to recognize tokens, but use methods like getLineTokens or getTokenAt to inspect tokens. That way, you don't need to wait for a highlight to happen.
Related
I've created a custom language extension for my own script language. I've written a tmlanguage file to tokenize my script and do custom highlighting. I created a hover-provider that currently only shows the word that is hovered for testing the provider itself. I want to react on the textmate scopes of the current position in this hover, like the vs code Developer tool "Inspect Editor Token and Scopes" does.
At the end I want to react to one particular scope whose value I want to read and show a corresponding image of this value in the hover.
Fore example a line in my script could look like:
setImage(dic_1/dic_2/testImg)
Now I want to show the image that correlates with the path in the brackets if I hover over it.
I tried to find something in the documentation (https://code.visualstudio.com/api/references/vscode-api#languages) if there is something that would help me but couldn't see anything related.
I tried to ask ChatGPT for help after he suggested "possible internal and not public available methods" it suggested to create a custom hover provider with the help of the library "oniguruma" and tokenize the document again.
However, this feels a bit like an overkill. If vscode has a internal tool that does return the textmate scopes I would guess there is a easy way to access those tokens.
I found this thread (Is there a way to find the textmate scope from within my VSCode extension language functions?) but I don't rally understand why I need to write another parser.
Is there any way to access this textmate scopes in a hover-provider?
I'm working on a taskpane add-in for Microsoft Word. So far, I'm able to place comments inside the Docx coming from the sidebar by abusing the OOXML insertion function.
I'm wondering if it's possible to monitor what the end user does with the comment.Is the commented deleted or accepted by the user? It is also significant to monitor the context of the comment - is that changed significantly?
I've considered the following approaches:
Create a ContentControl for the context of the comment to which events can be hooked that check for selection and changes. The downside here is that these ContentControl affect the UI in word and are probably not understood by our end-user. Are there more 'background' ways to do this without affecting the UI too much?
Create an interaction Hyperlink in the comment. I'm not sure if we can 'catch' this as an event or attach a JavaScript hook to this that actually makes it to the add-in?
Poll the document at set intervals to determine if something has happened to the comment or the context of the comment. I'm not sure what the correct hooks for this would be, and how to accurately localize all the changes across the document.
Is there an approach that I missed?
I'm aware that adding these comments is on the roadmap for the office-js, but this has been the case for a couple of years so I'm not sure what the timeframe is for this.
Edit
#Cindy thanks for taking the time to respond! With your help I've been able to get a functioning proof of concept using the hidden Content Control as a prepended OOXML snippet for the comment (So basically approach 1 combined with the OOXML insertion).
I can now capture some of the interaction by adding a binding to the content control and using the EventType.BindingDataChanged, something like this:
Office.context.document.bindings.addFromNamedItemAsync("MyContentControlTest", "text", {}, function (result) {
if (result.status == "succeeded") {
result.value.addHandlerAsync (
Office.EventType.BindingSelectionChanged, function()
{console.log("Don't touch me");}
)
})
})
It still feels a bit circumspect to attach a binding over a ContentControl, but I have not been able to add event listeners directly to the ContentControl. Given a named Content Control (MyContentControlTest) how could I attach an event like the OnDataChanged? And if i read correctly, this last feature is still in Preview, is there a way to find out what the expected release is?
I'm working on a side project using the Microsoft Office JavaScript APIs. I have been relying on the documentation to find my way around, but I've hit a wall trying to find something in the docs (perhaps it isn't there because it doesn't exist).
Recently I attempting to implement some functionality to highlight some text within a Word document. I don't want to modify the document, mind you; in other words I would rather not use something like ContentControl.insertHtml as that would change the actual content. What I want is to make the text temporarily highlighted (e.g., until the user clicks a "Cancel" button), much like what you see when you perform a search with Ctrl+F (and text matching your search is highlighted in yellow).
Is this possible using the Office JavaScript APIs?
Try getting a reference to the Range object and then setting Range.font.highlightcolor. Have a handler for the Cancel button click event that reverses the color change.
Here is a sample application that uses font.highlightcolor from the Office Javascript API. https://github.com/OfficeDev/Word-Add-in-JS-Redact/
I have a form with a single text field.
On submit I would like to display another form.
I can use RESPONSE.redirect() and pass it in the query string but I would rather not.
I don't want to use a SESSION variable.
I would like to display a second form which can read this value from the request variable.
I have looked at collective.z3cform.wizard but it is not obvious how to do this.
Trying to call the view() from the button handler does not seem to have any effect.
I fall in the same lack of functionality.
For what I know, z3c.form does not support this kind of traversing.
You may remember that this functionality worked well with CMFFormController.
Actually to do this, cmfformcontroller used session machinery.
So, you don't want to use session but that's the way. At least I do so, and I'm happy.
In this way there's no need of a wrapping tool like z3c.form.wizard.
hth,
alessandro.
collective.singing has a non-session based wizard which uses hidden fields to store results of intermediate steps.
I am making a custom textbox control and am thinking about adding keybindings in the constructor that execute commands to open and save files. I am also thinking about handling the find and replace dialog from within my textbox control.
Is there a reason I shouldn't do this?
--Edit--
I am planning on only using this control in my current application. One of the reasons I am thinking of doing this is to avoid binding to the textbox's Text property, since this binding seems like it would be just as inefficient as updating a string on the textbox's textchanged event.
Well, flexibility comes to mind. Consider the following scenarios, which would be impossible (or at least difficult) in your control:
You want to handle multiple or different methods of opening a file, but it depends on your application.
You want to use your textbox but limit the functionality -- e.g., Find/Replace is not allowed.
You want to change the behavior of any of that in one application but not the other. For example, in app A you want to tack on an extra slash to the end of the text, but in app B you want to add a custom folder name.
In general, I would consider something more generic. Something like a textbox has a specific purpose; enhancing that purpose is fine, but you're going beyond that. You're taking logic that rightly belongs to the app and putting it on a specific control. That limits what you can do with the control across multiple apps.
Of course, if you're writing a control specifically for one and only one app, you don't need to worry about these things. But I would still consider it a bad practice, myself.