Latest post of the previous page:
It's not in my code. I suppose I could modify it anyway, but I have no idea how difficult it would be.Filters
Filters
Version 0.06
- Added a support for unconfigured filters. This solves a common situation where the plugin had already been configured with some filters and then a new version with additional filters is introduced: In prior versions, the new filters would not become available until the user configured them. Now these filters are added automatically to the list of available filters. They should still be configured to allow their automatic execution through the "Autoselect" filter, but they will work manually without any configuration.
- Updated the plugin to a newer version of Dialog API. Among other things, this allows the plugin to properly react to resizing of the FAR's window.
- Minor fixes for compatibility with Delphi 10.1 and newer.
- BASE64 decoded was only available in debug builds (copy&paste error).
- Added a condition that the plugin is available to the Autoselect macro.
Filters
Yes, it is a trivial part, and it's Ok to me.
Great, so i go to
TPlugin.ReplaceSelectedContent
(am i on the right way to see the implementation?)
from there i understand that the Content
cimes from TPlugin.GetEditorInfo(EditorID: TIntPtr; out EditorInfo: TEditorInfo; out FileName, Content: string)
Filters
The "TopLine" variable here deals with the positioning of the cursor, not with the actual replacement. The replacement was already been done in TFarEditor.DeleteSelection and TFarEditor.InsertText.
Filters
.. shortly, this part makes problems in certain circumstances
The circumstances are, any empty line in selection, see my note in comments
The circumstances are, any empty line in selection, see my note in comments
Code: Select all
class function TFarEditor.GetSelection(EditorID: TIntPtr; out Str: string; out SelectionType: TIntPtr): boolean;
var
Info: TEditorInfo;
Row: TIntPtr;
Line, EOL: string;
SelStart, SelLength: TIntPtr;
EOLInSelection: boolean;
begin
Result := False;
if not GetInfo(EditorID, Info) then
Exit;
if Info.BlockType = BTYPE_NONE then
Exit;
Str := '';
SelectionType := Info.BlockType;
Row := Info.BlockStartLine;
while Row < Info.TotalLines do begin
if not GetString(EditorID, Row, Line, EOL, SelStart, SelLength, EOLInSelection) then
Break;
// this gives false break, when the line is in slection, but with zero length,
// so, the selection length also becomes zero-size,
// and it does not goes further, as it should:
if SelStart <= 0 then
Break;
if SelLength <= 0 then
Break;
Line := Copy(Line, SelStart, SelLength);
if EOLInSelection or (Info.BlockType = BTYPE_COLUMN) then
Str := Str + Line + EOL
else
Str := Str + Line;
Result := True;
Inc(Row);
end;
end;
Filters
pepak, i am sorry i left you in the middle without notice,
because i wanted to proof it in the detailed way possible,
so i wrote the proof in Lua-code, which is one-to-one translation from your Pascal code
The problem with empty lines in selection reproduced here the same exact way:
You may try it with all kind of selections,
with empty lines or without, and see the results immediatly.
I tested it making selections at the block comment in the bottom of the Lua- code
because i wanted to proof it in the detailed way possible,
so i wrote the proof in Lua-code, which is one-to-one translation from your Pascal code
The problem with empty lines in selection reproduced here the same exact way:
Code: Select all
Macro { description = "WRONG SELECTION HANDLING CODE EXAMPLE",
area = "Editor"; key = "AltS";
priority = 100; sortpriority = 100;
action = function()
-- ###
local edinf = editor.GetInfo()
local edstr = editor.GetString (edinf.EditorID, edinf.BlockStartLine)
local edpos = editor.SetPosition (edinf.EditorID, edinf.BlockStartLine, edstr.SelStart - 1)
local edsel = editor.GetSelection (edinf.EditorID)
local sz_sel_txt = ""
local ii_row = edinf.BlockStartLine
while ii_row < edinf.TotalLines
do
local ii_str = editor.GetString(edinf.EditorID, ii_r)
if ii_str.SelStart == -1
then ii_str.SelStart = 0
ii_str.SelLength= 0
ii_str.has_EOL = false
else if ii_str.SelEnd == -1
then ii_str.SelLength= string.len(ii_str.StringText)
ii_str.has_EOL = true
else ii_str.SelLength= ii_str.SelEnd - ii_str.SelStart
ii_str.has_EOL = false
end
end
if ii_str.SelStart <= 0 then break end
if ii_str.SelLength <= 0 then break end
sz_sel_txt = sz_sel_txt..string.sub(ii_str.StringText, ii_str.SelStart, ii_str.SelLength)..(ii_str.has_EOL and "\n" or "")
ii_row = ii_row + 1
end
far.Show(sz_sel_txt)
-- @@@
end;
}
--[[
111111111111111
dddddddd
3333333333
aaaaaaaa
fdffffffffff
324333333333333333333
--]]
with empty lines or without, and see the results immediatly.
I tested it making selections at the block comment in the bottom of the Lua- code
Last edited by citRiks on Mon 19 Oct, 2020 14:38, edited 4 times in total.
Filters
also, this line DelphiFar.pas:3689 of
why "TotalLines"? arent we want selection lines only?
TFarEditor.GetSelection(..)
function also does not looks justified: while Row < Info.TotalLines do begin
why "TotalLines"? arent we want selection lines only?
Filters
HaRT, just try your sort operstion with empty lines on the top of selection, you will see
also, i may reporduce the sort, and the problem this way:
It reminded me, using this UTF8+byte order mask will insert to editor those "BOMs",
in the middle of text, which is of course is not that should be there
also, i may reporduce the sort, and the problem this way:
Code: Select all
╔═════════════════════════════════════════════════════════════════ External Filter ══════════════════════════════════════════════════════════════════╗
║ Description: ║
║ Sort ↓║
║ File mask: (use comma as a separator) ║
║ * ↓║
║ [ ] Edit before use ║
║ Command template ║
║ sort %i ↓║
║ ║
║ Pass input as: Temp file ↓ (use %i in the te ║
║ Input encoding: UTF8 ↓ [x] Byte Order Mark ║
║ Get output from: STDOUT ↓ ║
║ Output encoding: UTF8 ↓ ║
║ ║
║ { OK } [ Cancel ] ║
╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
in the middle of text, which is of course is not that should be there
- HaRT
- Moderator
- Posts: 10806
- Joined: Tue 30 Aug, 2005 17:21
- Has thanked: 220 times
- Been thanked: 357 times
Filters
Right, I'm getting an instead of filters list.
@pepak If there are empty lines inside selection, I get various text corruption or lost lines. This is data loss that makes using filters (both built-in and external) simply dangerous.
Фар есть инструмент, а не нянька. © 2009 DrKnS
Filters
So, u found no bugs with applying on editor's selection?
From your point of view, no fix required, either .. ?
i am sorry, i just have not recognised the right timing of the answers.
My partial excuse comes from splitting the topic into the two (abt Delphi and abt the plugin).
Thanks to HaRT for pointing that out.
Last edited by citRiks on Mon 19 Oct, 2020 01:40, edited 1 time in total.
Filters
I am not yet ready to release a new version, but you may want to give this preliminary one a try: The selection problem (empty lines break the selection) is fixed. I didn't encounter any unexpected behavior with the UTF8 handling - I am, of course, not removing BOMs from the middle of the text because that's the responsibility of the producer, not my plugin; I have no way of knowing whether that byte sequence is a BOM or an actual binary data that needs to be returned.
Please check this version out and if it works for you, let me know. If you know of any other errors, please let me know as well, so that I can make a version with all known errors fixed. If I don't get any new bug reports, I expect to create version 0.07 next weekend.
Please check this version out and if it works for you, let me know. If you know of any other errors, please let me know as well, so that I can make a version with all known errors fixed. If I don't get any new bug reports, I expect to create version 0.07 next weekend.
- Attachments
-
- filters-0.06-fix1.7z
- (547.61 KiB) Downloaded 97 times
Filters
To may way of thinking,
if we work on editor selection, it can be only text data, or supposed to be text data, not binary.
I would say what those first two bytes of text have very easy detectable signature.
It is always first two bytes, and always only very certain bytes.
Detecting of UTF8 strings is necessary for any text handling nowadays.
Here is the Lua-code for it, can be easily translated to Pascal.
it is simple and bug-free (er.. well, should be),
handling any kind of unicode (not only UTF8):
Code: Select all
local fnc_det_bom_str = function(str_head)
local boms = {
{name = "ASCI", code = ""},
{name = "32LE", code = '\255\254\0\0'}, -- utf32le
{name = "32BE", code = '\0\0\254\255'}, -- utf32be
{name = "16LE", code = '\255\254'}, -- utf16le
{name = "16BE", code = '\254\255'}, -- utf16be
{name = "UTF8", code = '\239\187\191'} -- utf8
}
local str_bom
local res = 1
for ii = #boms, 3, -1
do str_bom = string.sub(str_head, 1, #(boms[ii].code))
if str_bom == boms[ii].code
then if ii == 4 and str_bom == boms[2].code then ii = 2 end
res = ii
break
end
end
return boms[res].name, boms[res].code
end
local fnc_read_header_text = function(file_name)
local fp = io.open(filename)
if not fp then return end
local s = fp:read(512)
fp:close()
return s:gsub("%s+", " "):match("[%w_].*")
end
local fnc_det_bom_file = function(file_name)
local str_head, bom_name, bom_code
local fHnd = io.open(file_name, "rb")
if fHnd
then str_head = fHnd:read(4) or ''
fHnd:close()
bom_name, bom_code = Xer0X.fnc_det_bom_str(str_head)
end
return bom_name, bom_code
end
Last edited by citRiks on Sun 25 Oct, 2020 20:59, edited 2 times in total.