Skip to content

Commit 4627069

Browse files
authored
Merge pull request #1098 from MKadaner/mzk/gh-1000/dynamic-contents-of-fixed-menu-columns
gh-1000: Do not materialize text coordinates in Find All menu items.
2 parents f9be4f3 + 06953f4 commit 4627069

8 files changed

Lines changed: 106 additions & 113 deletions

File tree

extra/Addons/Macros/Edit.SyncEditorAndFindAllMenu.lua

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,6 @@ local function HighlighText()
107107
editor.Redraw(EditorInfo.EditorID);
108108
end
109109

110-
-- Will be removed when items do not contain found coordinates inline
111-
local function GetLineNumberFixedColumns(FarDialogEvent, LineNumber)
112-
local ItemText = FarDialogEvent.hDlg:send(F.DM_LISTGETITEM, 1, 1).Text
113-
114-
local LineNumberColumnWidth = 0
115-
if ItemText then
116-
LineNumberColumnWidth = #(ItemText:match("^(%s*%d+)%s") or "")
117-
end
118-
119-
return string.format("%" .. LineNumberColumnWidth .. "d ", LineNumber)
120-
end
121-
122110
local function SetupMenuAndEditor(FarDialogEvent)
123111
local SelectPos = 1
124112

@@ -135,10 +123,7 @@ local function SetupMenuAndEditor(FarDialogEvent)
135123
if SelectPos == ItemsNumber + 1 -- All occurrences precede the cursor position
136124
-- or the current editor line does not containing an occurrence
137125
or Menu.GetItemExtendedData(FarDialogEvent.hDlg, SelectPos).Line ~= EditorInfo.CurLine then
138-
FarDialogEvent.hDlg:send(F.DM_LISTINSERT,
139-
1,
140-
{ Index = SelectPos,
141-
Text = GetLineNumberFixedColumns(FarDialogEvent, EditorInfo.CurLine) .. Editor.GetStr(EditorInfo.CurLine) })
126+
FarDialogEvent.hDlg:send(F.DM_LISTINSERT, 1, { Index = SelectPos, Text = Editor.GetStr(EditorInfo.CurLine) })
142127
Menu.SetItemExtendedData(FarDialogEvent.hDlg, SelectPos, { Line = EditorInfo.CurLine, Position = EditorInfo.CurPos, Length = 0 })
143128
ItemsNumber = ItemsNumber + 1
144129
end

far/changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
--------------------------------------------------------------------------------
2+
MZK 2026-05-10 12:27:04-04:00 - build 6683
3+
4+
1. gh-1000: Do not materialize text coordinates in Find All menu items.
5+
Instead of extracting line and position of the found pattern
6+
from the item's text, macros should use Menu.GetItemExtendedData.
7+
18
--------------------------------------------------------------------------------
29
drkns 2026-05-09 12:59:44+01:00 - build 6682
310

far/editor.cpp

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,10 +3526,7 @@ namespace
35263526

35273527
void add_item(FindCoord FoundCoords, string_view ItemText)
35283528
{
3529-
menu_item_ex Item{ far::format(L"{:{}}{:{}}{}"sv,
3530-
FoundCoords.Line + 1, m_LineNumColumnMaxWidth,
3531-
FoundCoords.Pos + 1, m_FoundPosColumnMaxWidth,
3532-
ItemText) };
3529+
menu_item_ex Item{ string{ ItemText } };
35333530
Item.Annotations.emplace_back(FoundCoords.Pos, segment::length_tag{ FoundCoords.SearchLen });
35343531
Item.ComplexUserData = FoundCoords;
35353532
m_Menu->AddItem(Item);
@@ -3554,25 +3551,39 @@ namespace
35543551
m_Menu->SetHelp(L"FindAllMenu"sv);
35553552
m_Menu->SetId(EditorFindAllListId);
35563553

3557-
const short LineNumColumnWidth{ radix10_formatted_width(m_MaxLineNum + 1) };
3558-
const short FoundPosColumnWidth{ radix10_formatted_width(m_MaxFoundPos + 1) };
3559-
const short LineNumColumnStart{ static_cast<short>(m_LineNumColumnMaxWidth - LineNumColumnWidth) };
3560-
const short FoundPosColumnStart{ static_cast<short>(m_LineNumColumnMaxWidth + m_FoundPosColumnMaxWidth - FoundPosColumnWidth) };
3561-
const short ItemTextStart{ static_cast<short>(m_LineNumColumnMaxWidth + m_FoundPosColumnMaxWidth) };
3562-
m_Menu->SetFixedColumns(
3554+
const auto LineNumColumnWidth{ radix10_formatted_width(m_MaxLineNum + 1) };
3555+
const auto FoundPosColumnWidth{ radix10_formatted_width(m_MaxFoundPos + 1) };
3556+
m_Menu->ListBox().RegisterFixedColumnsProvider(
35633557
{
35643558
{
3565-
.TextSegment{ LineNumColumnStart, segment::length_tag{ LineNumColumnWidth } },
3559+
.MaxWidth = LineNumColumnWidth,
35663560
.CurrentWidth = LineNumColumnWidth,
3567-
.Separator = BoxSymbols[BS_V1]
3561+
.Separator = BoxSymbols[BS_V1],
3562+
.ColumnId = 0,
35683563
},
35693564
{
3570-
.TextSegment{ FoundPosColumnStart, segment::length_tag{ FoundPosColumnWidth } },
3565+
.MaxWidth = FoundPosColumnWidth,
35713566
.CurrentWidth = FoundPosColumnWidth,
3572-
.Separator = BoxSymbols[BS_V1]
3567+
.Separator = BoxSymbols[BS_V1],
3568+
.ColumnId = 1,
35733569
},
35743570
},
3575-
segment::ray(ItemTextStart)
3571+
[](const menu_item_ex& Item, const VMenu::fixed_column_t& Column)
3572+
{
3573+
if (const auto* Coord{ std::any_cast<FindCoord>(&Item.ComplexUserData) })
3574+
{
3575+
switch (Column.ColumnId)
3576+
{
3577+
case 0: // Line Number
3578+
return far::format(L"{:{}}"sv, Coord->Line + 1, Column.MaxWidth);
3579+
3580+
case 1: // Found Position
3581+
return far::format(L"{:{}}"sv, Coord->Pos + 1, Column.MaxWidth);
3582+
}
3583+
}
3584+
3585+
return string{};
3586+
}
35763587
);
35773588
m_Menu->ListBox().RegisterExtendedDataProvider(
35783589
[](const menu_item_ex& Item, VMenu::extended_item_data& ExtendedData)
@@ -4022,8 +4033,11 @@ void Editor::DoSearchReplace(const SearchReplaceDisposition Disposition)
40224033
if (SelectedPos == -1)
40234034
break;
40244035

4025-
SelectFoundPattern(*FindAllList->m_Menu->GetComplexUserDataPtr<FindCoord>(SelectedPos));
4026-
Refresh();
4036+
if (const auto* Coord{ FindAllList->m_Menu->GetComplexUserDataPtr<FindCoord>(SelectedPos) })
4037+
{
4038+
SelectFoundPattern(*Coord);
4039+
Refresh();
4040+
}
40274041
}
40284042
break;
40294043

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

40884102
if(ExitCode >= 0)
40894103
{
4090-
SelectFoundPattern(*FindAllList->m_Menu->GetComplexUserDataPtr<FindCoord>(ExitCode));
4091-
Show();
4104+
if (const auto* Coord{ FindAllList->m_Menu->GetComplexUserDataPtr<FindCoord>(ExitCode) })
4105+
{
4106+
SelectFoundPattern(*Coord);
4107+
Show();
4108+
}
40924109
}
40934110
}
40944111

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

4141-
const auto ThisEditorCoord{ std::any_cast<FindCoord>(Item.ComplexUserData) };
4158+
const auto* ThisEditorCoord{ std::any_cast<FindCoord>(&Item.ComplexUserData) };
4159+
if (!ThisEditorCoord) continue;
41424160

4143-
if (ThisEditorCoord.Line != ThisEditorLastLine)
4161+
if (ThisEditorCoord->Line != ThisEditorLastLine)
41444162
{
4145-
ThisEditorLastLine = ThisEditorCoord.Line;
4163+
ThisEditorLastLine = ThisEditorCoord->Line;
41464164

4147-
const auto CurString{ GetStringByNumber(ThisEditorCoord.Line) };
4165+
const auto CurString{ GetStringByNumber(ThisEditorCoord->Line) };
41484166
const auto NewEditorLine{ NewEditor.InsertString(CurString->GetString(), NewEditor.LastLine()) };
41494167
NewEditorLine->SetEOL(CurString->GetEOL());
41504168
}
41514169

41524170
if (static_cast<intptr_t>(Index) == ExitCode)
41534171
{
4154-
const auto CurrentFoundCoord{ *ListBox.GetComplexUserDataPtr<const FindCoord>(ExitCode) };
4155-
NewEditorFoundCoord =
4172+
if (const auto* CurrentFoundCoord{ ListBox.GetComplexUserDataPtr<const FindCoord>(ExitCode) })
41564173
{
4157-
.Line = std::prev(NewEditor.LastLine()).Number(),
4158-
.Pos = CurrentFoundCoord.Pos,
4159-
.SearchLen = CurrentFoundCoord.SearchLen
4160-
};
4174+
NewEditorFoundCoord =
4175+
{
4176+
.Line = std::prev(NewEditor.LastLine()).Number(),
4177+
.Pos = CurrentFoundCoord->Pos,
4178+
.SearchLen = CurrentFoundCoord->SearchLen
4179+
};
4180+
}
41614181
}
41624182
}
41634183

far/vbuild.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6682
1+
6683

0 commit comments

Comments
 (0)