- August 30, 2016 at 3:51 pm #21031
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?September 6, 2016 at 11:30 pm #21032
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?September 21, 2016 at 6:41 am #21073
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.
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);
You must be logged in to reply to this topic.