texstudio icon indicating copy to clipboard operation
texstudio copied to clipboard

(?highlighted-as:numbers) is not working

Open fuhaoshuo opened this issue 3 years ago • 5 comments

Environment

  • TeXstudio: 4.0.0alpha2
  • Qt: 5.15.2
  • OS: Windows 10
  • TeX distribution: not relevant

Problem already happened for TeXstudio version 3.0.4(Qt 5.12.3). same result for (?highlighted-as:picture), etc. works fine for (?highlighted-as:comment), etc.

Expected behavior

The script will run if it matches the trigger in math environment. Like the previous version 2.12.16.

Actual behavior

Nothing happened.

How to reproduce

add (?highlighted-as:numbers) before the trigger of a macro.

fuhaoshuo avatar Jun 20 '21 19:06 fuhaoshuo

the issue comes from a change in logic. Math (and now also comments) are highlighted in a parallel thread, so that the main thread does not see it as it is not yet highlighted...

sunderme avatar Jun 29 '21 17:06 sunderme

A possible workaround:

  1. create a list of mathematical environments you are interested in (I used a dictionary because I had a dictionary already)
  2. get the environment using editor.document().getLastEnvName(line)
  3. check if your environment is in the list of mathematical environments
math_env = {
"align*": "eq",
"align": "eq",
"equation": "eq",
"coment": "cmnt",
"exemp": "exmp",
"math": "math"
}

// CHECK IF INSIDE MATH ENVIRONMENT
var line = cursor.lineNumber()
var env = editor.document().getLastEnvName(line)

if ( env in math_env){

// YOUR OLD SCRIPT GOES HERE

}

This is probably much slower, but get the job done.

I also tried to include (?not-highlighted-as:normal) in order to avoid running this in such cases, but could not get it to work.

r-menezes avatar Aug 13 '21 01:08 r-menezes

Any progress on this problem? It is not only (?highlighted-as: *) itself that breaks. It also prevents the macro from triggering even after the prepended scope limit removed, until restarting TexStudio.

w568w avatar Sep 22 '22 05:09 w568w

no progress

sunderme avatar Sep 23 '22 18:09 sunderme