Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30062
    Reg Johnson
    Participant

    After running a negative filter, the negative filter flag is set and new filters are also negative.

    How do I reset the flag (regardless of current state) in a macro so that subsequent filter commands are “positive” and not “negative”?

    #30063
    Patrick C
    Participant
    #title = "Set the negative filter flag to inactive"
    #language = "V8"
    #async = "off"
    
    // get the filter toolbar’s negative status (id 3916)
    let negFilterStatus = editor.QueryStatusByID(3916);
    
    // if negative is enabled → disable by toggling
    if ((negFilterStatus & eeStatusEnabled) === eeStatusEnabled) {
      // case negative is enabled → run the toggle command
      editor.ExecuteCommandByID(3916);
    }

    EmEditor Help: Negative (Filter Toolbar) command
    EmEditor Help: QueryStatusByID Method

    Regarding (negFilterStatus & eeStatusEnabled) === eeStatusEnabled:
    EmEditor uses bitwise flags for statuses. The & is a bitwise and.

    #30064
    Patrick C
    Participant

    Correction: One must test for eeStatusLatched.

    #title = "Set the negative filter flag to inactive"
    #language = "V8"
    #async = "off"
    
    // get the filter toolbar’s negative status (id 3916)
    let negFilterStatus = editor.QueryStatusByID(3916);
    
    // if negative is enabled → disable by toggling
    if ((negFilterStatus & eeStatusLatched) === eeStatusLatched  ) {
      // case negative is enabled → run the toggle command
      editor.ExecuteCommandByID(3916);
    }

    EmEditor Help: Negative (Filter Toolbar) command
    EmEditor Help: QueryStatusByID Method

    Regarding (negFilterStatus & eeStatusLatched) === eeStatusLatched
    EmEditor uses bitwise flags for statuses. The & is a bitwise and.

    #30065
    Reg Johnson
    Participant

    Thanks!

    I wish there was a simple “one-line” way to just reset all flags.

    #30066
    Reg Johnson
    Participant

    Actually, I am not sure how to make this work. I am using vbscript.
    I tried running this command after doing a negative filter:
    “editor.ExecuteCommandByID(3912)”

    And the negative filter was still set and any search resulted in a negative search.

    #30067
    Patrick C
    Participant

    The VBScript Command is
    editor.ExecuteCommandByID 3916
    EmEditor Help: Negative (Filter Toolbar) command

    ——————————————————————-
    The JavaScript above expressed as VBScript is

    #title = "Set the negative filter flag to inactive"
    #language = "VBScript"
    #async = "off"
    
    ' get the filter toolbar’s negative status (id 3916)
    Dim negFilterStatus
    negFilterStatus = editor.QueryStatusByID(3916)
    
    ' if negative is enabled -> disable by toggling
    If ((negFilterStatus And eeStatusLatched) = eeStatusLatched) Then
      ' case negative is enabled → run the toggle command
      editor.ExecuteCommandByID 3916
    End If

    ——————————————————————-
    VBScript code to set all filters to 0 is (its ugly, couldn`t think of something better):

    #title = "Set the negative filter flag to inactive"
    #language = "VBScript"
    #async = "off"
    
    ' reset the filters list
    Dim filtersList
    Set filtersList = document.filters
    filtersList.Clear
    filtersList.Add "dummy", False, 0, 0   ' add a single item with all flags set to 0 (off)
    document.filters = filtersList         ' apply the filter → flags are now 0
    filtersList.Clear                      ' remove the filter again (removes ‘dummy’)
    document.filters = filtersList         ' empty filter + the flags stay as they are

    ——————————————————————-
    Note that VBScript is deprecated.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.