Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #21031
    LifeTimer
    Participant

    I’m using a macro (in Cell Selection Mode) to select all the data in the column where the “cell cursor” is currently at. It looks like this:

    	document.selection.SetActivePoint(eePosCell, document.selection.GetActivePointX(eePosCell), 2, false);
    	document.selection.SetActivePoint(eePosCell, document.selection.GetActivePointX(eePosCell), document.GetLines() - 1, true);
    

    It works great when there is no active filter, but as soon as any line at the end of the file is currently filtered-out, it won’t work. It will then instead select all the columns including and to the left of the column where the “cell cursor” is currently at.

    The simple explanation for this is that the expression “document.GetLines() – 1” will not move the cursor from the last (empty) line above it in the filtered data (because the line number of that line will still be less than “document.GetLines() – 1” if any lines have been filtered-out inbetween the end of the document and the last visible (= non-filtered out) line in the document). Thus, the cell cursor will “snap left” on the very last line of the file (which is always empty, therefore bringing the cell cursor all the way to the left, consequently selecting also all the columns to the left of the intended column).

    So, my question is therefore: Is there any way to get the line numbers of only the visible lines (i.e. those that are not hidden by the filter) in a file, from a macro?

    If not, how can I go about selecting the entire contents of a single column from a macro in the above described scenario?

    Example data (with example line numbers to the left):

    1: col1;col2;col3
    2: 1;2;3
    3: 11;22;33
    4: 111;222;333
    10:

    In this case, lines 5-9 of the file have been filtered-out by a filter expression, therefore not being visible in the editor window.

    So, what I want in this example is to get the number of the last visible line (i.e. nr 4, which is the last visible line before the very last line which in this case is nr 10, where the last one is always empty without any cells, except the “artificial” cell being placed to the very left), or any other method to reliably select the entire data contents (i.e. rows 2-4) of this column.

    Are any of these two things currently possible from EmEditor macros, or could you otherwise possibly add the possibility to do any of these two things?

    #21032
    Yutaka Emura
    Keymaster

    Hello LifeTimer,

    The following macro should get the number of visible lines.

    n = document.GetLines( eeGetLineView );

    Can you please try and let me know if you have further questions?

    #21073
    LifeTimer
    Participant

    Thanks for your reply!

    Unfortunately, this is not a solution for the problem. :-(

    Even though it works when only rows at the very end of the file has been filtered away, it does not work if any other rows higher up in the document has been filtered away also.

    Example:

    Unfiltered document contents:

    col1,col2,col3
    1,2,3
    aaa,bbb,ccc
    aaa,bbb,ccc
    11,22,33
    111,222,333
    xxx,yyy,zzz
    xxx,yyy,zzz
    xxx,yyy,zzz
    xxx,yyy,zzz
    xxx,yyy,zzz

    After filtering the last rows (e.g. filtering away “xxx”):

    col1,col2,col3
    1,2,3
    aaa,bbb,ccc
    aaa,bbb,ccc
    11,22,33
    111,222,333

    As mentioned above, the selection macro in my first post (modified with your suggestion of the eeGetLineView parameter to the document.GetLines() method) does indeed work now, BUT, if we also filter away some other lines, e.g. the ones containing “aaa”, we get the following visible document contents:

    col1,col2,col3
    1,2,3
    11,22,33
    111,222,333

    And if we then try to run the macro, the selection is cut short and does not cover the full column (the last line is not selected, and the more lines we filter away, the more lines will not be selected at the bottom).

    The problem is apparently that the SetActivePoint() method uses absolute line numbers (i.e. ignoring that rows have been filtered away), while the document.GetLines() method always returns a total count of lines (visible or not). So we would either need the SetActivePoint() method to also be able to use relative line numbers (i.e. after filtering), or need some completely other method to return the absolute line number of the last visible (non empty) line (for example named “document.GetLastVisibleLineNumber()”), in order to be able to perform this simple operation of selecting the contents of a column?

    Here is the full macro code, modified with your suggested eeGetLineView parameter, for reference:

    document.selection.SetActivePoint(eePosCell, document.selection.GetActivePointX(eePosCell), 2, false);
    document.selection.SetActivePoint(eePosCell, document.selection.GetActivePointX(eePosCell), document.GetLines(eeGetLineView) - 1, true);
    #21081
    Yutaka Emura
    Keymaster

    Hello,

    document.GetLines(eeGetLineView);

    should always return the number of only visible lines. Please make sure you add the “eeGetLinesView” flag as written above.

    Can you make sure you use the latest version of EmEditor?

    If the problem persists, please write the issue with a very simple example with a few sentences (as simple as possible).

    Thank you,

    #21082
    LifeTimer
    Participant

    Sorry if I was unclear. Yes, the eeGetLineView parameter to the document.GetLines() method does indeed return the number of visible lines. Unfortunately this is not the problem though.

    The problem is that when I then want to use this number to move the cell cursor in the filtered document data, it turns out that the document.selection.SetActivePoint() method only uses absolute line numbers (i.e. the line numbers that are listed to the left in EmEditor, contrary to the target line’s number in the order of visible lines from the top of the document), and these absolute line numbers do not change when filtering the data, which in turn means that the result returned from document.GetLines(eeGetLineView) is sadly of no use at all for knowing how to make document.selection.SetActivePoint() position the cell cursor on the last visible line of the filtered document.

    Allow me to completely rephrase the question for you though, and you will most likely stumble upon this problem yourself when answering this question if nothing else:

    Could you please tell me how to write a macro in EmEditor that performs the simple operation of selecting all visible cells in the current column (except the header line) in an arbitrarily filtered document in Cell Selection Mode?

    #21086
    Yutaka Emura
    Keymaster

    Hello LifeTimer,

    Thanks for clarification.

    You can use:

    editor.ExecuteCommandByID(4461);

    to select the current column without headings.

    Thank you,

    #21087
    LifeTimer
    Participant

    Thanks!

    I’d still recommend to implement “real” macro support for it though (e.g. by making the document.selection.SetActivePoint() method optionally be able to use relative visible line numbers instead of only absolute line numbers). :-)

    #21093
    Yutaka Emura
    Keymaster

    Hello LifeTimer,

    On the next version (v16.2.0 beta 2), you can use eePosCellView flag to specify the coordinate in Cell View mode. For example:

    document.selection.SetActivePoint( eePosCellView, 1, 7, false );

    will set the active cell at (1,7) in the view.

    Thank you,

    #21094
    LifeTimer
    Participant

    Excellent, thanks for your responsiveness, as always!

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