Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions extra/Addons/Macros/Edit.SyncEditorAndFindAllMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,6 @@ local function HighlighText()
editor.Redraw(EditorInfo.EditorID);
end

-- Will be removed when items do not contain found coordinates inline
local function GetLineNumberFixedColumns(FarDialogEvent, LineNumber)
local ItemText = FarDialogEvent.hDlg:send(F.DM_LISTGETITEM, 1, 1).Text

local LineNumberColumnWidth = 0
if ItemText then
LineNumberColumnWidth = #(ItemText:match("^(%s*%d+)%s") or "")
end

return string.format("%" .. LineNumberColumnWidth .. "d ", LineNumber)
end

local function SetupMenuAndEditor(FarDialogEvent)
local SelectPos = 1

Expand All @@ -135,10 +123,7 @@ local function SetupMenuAndEditor(FarDialogEvent)
if SelectPos == ItemsNumber + 1 -- All occurrences precede the cursor position
-- or the current editor line does not containing an occurrence
or Menu.GetItemExtendedData(FarDialogEvent.hDlg, SelectPos).Line ~= EditorInfo.CurLine then
FarDialogEvent.hDlg:send(F.DM_LISTINSERT,
1,
{ Index = SelectPos,
Text = GetLineNumberFixedColumns(FarDialogEvent, EditorInfo.CurLine) .. Editor.GetStr(EditorInfo.CurLine) })
FarDialogEvent.hDlg:send(F.DM_LISTINSERT, 1, { Index = SelectPos, Text = Editor.GetStr(EditorInfo.CurLine) })
Menu.SetItemExtendedData(FarDialogEvent.hDlg, SelectPos, { Line = EditorInfo.CurLine, Position = EditorInfo.CurPos, Length = 0 })
ItemsNumber = ItemsNumber + 1
end
Expand Down
7 changes: 7 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
--------------------------------------------------------------------------------
MZK 2026-05-10 12:27:04-04:00 - build 6683

1. gh-1000: Do not materialize text coordinates in Find All menu items.
Instead of extracting line and position of the found pattern
from the item's text, macros should use Menu.GetItemExtendedData.

--------------------------------------------------------------------------------
drkns 2026-05-09 12:59:44+01:00 - build 6682

Expand Down
78 changes: 49 additions & 29 deletions far/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3526,10 +3526,7 @@ namespace

void add_item(FindCoord FoundCoords, string_view ItemText)
{
menu_item_ex Item{ far::format(L"{:{}}{:{}}{}"sv,
FoundCoords.Line + 1, m_LineNumColumnMaxWidth,
FoundCoords.Pos + 1, m_FoundPosColumnMaxWidth,
ItemText) };
menu_item_ex Item{ string{ ItemText } };
Item.Annotations.emplace_back(FoundCoords.Pos, segment::length_tag{ FoundCoords.SearchLen });
Item.ComplexUserData = FoundCoords;
m_Menu->AddItem(Item);
Expand All @@ -3554,25 +3551,39 @@ namespace
m_Menu->SetHelp(L"FindAllMenu"sv);
m_Menu->SetId(EditorFindAllListId);

const short LineNumColumnWidth{ radix10_formatted_width(m_MaxLineNum + 1) };
const short FoundPosColumnWidth{ radix10_formatted_width(m_MaxFoundPos + 1) };
const short LineNumColumnStart{ static_cast<short>(m_LineNumColumnMaxWidth - LineNumColumnWidth) };
const short FoundPosColumnStart{ static_cast<short>(m_LineNumColumnMaxWidth + m_FoundPosColumnMaxWidth - FoundPosColumnWidth) };
const short ItemTextStart{ static_cast<short>(m_LineNumColumnMaxWidth + m_FoundPosColumnMaxWidth) };
m_Menu->SetFixedColumns(
const auto LineNumColumnWidth{ radix10_formatted_width(m_MaxLineNum + 1) };
const auto FoundPosColumnWidth{ radix10_formatted_width(m_MaxFoundPos + 1) };
m_Menu->ListBox().RegisterFixedColumnsProvider(
{
{
.TextSegment{ LineNumColumnStart, segment::length_tag{ LineNumColumnWidth } },
.MaxWidth = LineNumColumnWidth,
.CurrentWidth = LineNumColumnWidth,
.Separator = BoxSymbols[BS_V1]
.Separator = BoxSymbols[BS_V1],
.ColumnId = 0,
},
{
.TextSegment{ FoundPosColumnStart, segment::length_tag{ FoundPosColumnWidth } },
.MaxWidth = FoundPosColumnWidth,
.CurrentWidth = FoundPosColumnWidth,
.Separator = BoxSymbols[BS_V1]
.Separator = BoxSymbols[BS_V1],
.ColumnId = 1,
},
},
segment::ray(ItemTextStart)
[](const menu_item_ex& Item, const VMenu::fixed_column_t& Column)
{
if (const auto* Coord{ std::any_cast<FindCoord>(&Item.ComplexUserData) })
{
switch (Column.ColumnId)
{
case 0: // Line Number
return far::format(L"{:{}}"sv, Coord->Line + 1, Column.MaxWidth);

case 1: // Found Position
return far::format(L"{:{}}"sv, Coord->Pos + 1, Column.MaxWidth);
}
}

return string{};
}
);
m_Menu->ListBox().RegisterExtendedDataProvider(
[](const menu_item_ex& Item, VMenu::extended_item_data& ExtendedData)
Expand Down Expand Up @@ -4022,8 +4033,11 @@ void Editor::DoSearchReplace(const SearchReplaceDisposition Disposition)
if (SelectedPos == -1)
break;

SelectFoundPattern(*FindAllList->m_Menu->GetComplexUserDataPtr<FindCoord>(SelectedPos));
Refresh();
if (const auto* Coord{ FindAllList->m_Menu->GetComplexUserDataPtr<FindCoord>(SelectedPos) })
{
SelectFoundPattern(*Coord);
Refresh();
}
}
break;

Expand Down Expand Up @@ -4087,8 +4101,11 @@ void Editor::DoSearchReplace(const SearchReplaceDisposition Disposition)

if(ExitCode >= 0)
{
SelectFoundPattern(*FindAllList->m_Menu->GetComplexUserDataPtr<FindCoord>(ExitCode));
Show();
if (const auto* Coord{ FindAllList->m_Menu->GetComplexUserDataPtr<FindCoord>(ExitCode) })
{
SelectFoundPattern(*Coord);
Show();
}
}
}

Expand Down Expand Up @@ -4138,26 +4155,29 @@ void Editor::SaveFoundItemsToNewEditor(const VMenu& ListBox, const bool Matching
{
if (Item.Flags & FilterFlags) continue;

const auto ThisEditorCoord{ std::any_cast<FindCoord>(Item.ComplexUserData) };
const auto* ThisEditorCoord{ std::any_cast<FindCoord>(&Item.ComplexUserData) };
if (!ThisEditorCoord) continue;

if (ThisEditorCoord.Line != ThisEditorLastLine)
if (ThisEditorCoord->Line != ThisEditorLastLine)
{
ThisEditorLastLine = ThisEditorCoord.Line;
ThisEditorLastLine = ThisEditorCoord->Line;

const auto CurString{ GetStringByNumber(ThisEditorCoord.Line) };
const auto CurString{ GetStringByNumber(ThisEditorCoord->Line) };
const auto NewEditorLine{ NewEditor.InsertString(CurString->GetString(), NewEditor.LastLine()) };
NewEditorLine->SetEOL(CurString->GetEOL());
}

if (static_cast<intptr_t>(Index) == ExitCode)
{
const auto CurrentFoundCoord{ *ListBox.GetComplexUserDataPtr<const FindCoord>(ExitCode) };
NewEditorFoundCoord =
if (const auto* CurrentFoundCoord{ ListBox.GetComplexUserDataPtr<const FindCoord>(ExitCode) })
{
.Line = std::prev(NewEditor.LastLine()).Number(),
.Pos = CurrentFoundCoord.Pos,
.SearchLen = CurrentFoundCoord.SearchLen
};
NewEditorFoundCoord =
{
.Line = std::prev(NewEditor.LastLine()).Number(),
.Pos = CurrentFoundCoord->Pos,
.SearchLen = CurrentFoundCoord->SearchLen
};
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6682
6683
Loading
Loading