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
1 change: 1 addition & 0 deletions Build/Notepad3.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ SettingsVersion=5
;AtomicFileSave=true
;ExitOnESCSkipLevel=2
;ZoomTooltipTimeout=3200 ;in [msec]
;ZoomTooltipPosition=0 ;(0=upper-left, 1=upper-right, 2=near caret, 3=near mouse)
;WrapAroundTooltipTimeout=2000 ;in [msec]
;LargeIconScalePrecent=150
;DarkModeBkgColor=0x1F1F1F
Expand Down
2 changes: 2 additions & 0 deletions agent-trail/architecture/codebase-and-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Before an approved vendored-library change, consult the [Lexilla patch registry]

### Dynamic string/path buffer lifetime

`StrgCreate(NULL)` can return a valid handle without allocating its text buffer; `StrgGet(h) == NULL` before initialization is normal, not proof of allocation failure. Initialize the fresh handle with `StrgReset(h, text)` and check its result (`> 0`) before using the text ([source](../../src/DynStrg.c#L432-L473): `StrgCreate`, `StrgReset`, `StrgGet`).

Never use a pointer returned by `Path_WriteAccessBuf()` / `StrgWriteAccessBuf()` after an operation that may reallocate or swap the same handle's buffer. Examples include `Path_CanonicalizeEx`, `Path_Swap` / `StrgSwap`, `Path_ExpandEnvStrings` / `ExpandEnvironmentStrgs`, `Path_Append` / `Path_Reset`, `StrgCat` / `StrgInsert` / `StrgFormat` / `StrgReset`, and `Path_NormalizeEx` / `Path_AbsoluteFromApp` / `Path_RelativeToApp`.

- For read-only access afterward, use `Path_Get(h)` / `StrgGet(h)`.
Expand Down
12 changes: 10 additions & 2 deletions agent-trail/architecture/scintilla-api-usage.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Scintilla API Usage Notes

When to read: Replacing home-grown `Edit.c` code with Scintilla messages
When to read: Scintilla message replacements, zoom call-tip positioning, or Scintilla upgrades

Verified constraints to check before replacing home-grown `src\Edit.c` code with a Scintilla message. Wrapper rules are in [Codebase and conventions](codebase-and-conventions.md).
Constraints for first-party Scintilla calls and native zoom call-tip positioning. Wrapper rules are in [Codebase and conventions](codebase-and-conventions.md).

## Reading document text

Expand All @@ -18,6 +18,14 @@ Verified constraints to check before replacing home-grown `src\Edit.c` code with
| `SCI_REPLACETARGETMINIMAL` | `Sci_ReplaceTargetTestChgHist` (`src\SciCall.h`) uses it only when change history is enabled; otherwise a full `SCI_REPLACETARGET`. |
| `SCI_MARKERNEXT` / `SCI_MARKERPREVIOUS` | Do not see change-history markers (21-24); `_MarkerNext` / `_MarkerPrevious` in `src\Edit.c` scan linearly for them. |

## Native zoom call-tip discovery

- Preserve the combined discovery checks in `_FindZoomCallTip` / `_PositionZoomCallTip`: enumerate the current thread's windows, match the editor's top-level owner (`GA_ROOT`), require class `CallTip`, and compare window extra bytes at offset zero with the nonzero `SciCall_GetDirectPointer()`. Windows promotes the child editor's popup owner to its top-level window; owner matching alone cannot distinguish editors sharing that window ([implementation](../../src/Notepad3.c#L13665-L13692)).
- Never cache the popup HWND across cancellation. `CallTip::CallTipCancel` destroys the native window; rediscover it after showing the next tip ([lifetime](../../scintilla/src/CallTip.cxx#L312-L317)).
- Revalidate this contract when upgrading Scintilla: the class and instance-pointer storage are vendored Win32 internals, not a public popup-HWND API. `ScintillaWin::CTWndProc` stores the instance via `SetWindowPointer`, whose offset-zero storage must still agree with `SCI_GETDIRECTPOINTER` ([creation](../../scintilla/win32/ScintillaWin.cxx#L4134-L4147), [storage](../../scintilla/win32/PlatWin.cxx#L78-L84), [direct pointer](../../scintilla/win32/ScintillaWin.cxx#L2278-L2279)).

Ownership isolation and popup recreation are exercised by `test\TestZoomTooltipPosition.cpp` using hidden Win32 windows. Those checks do not establish visible rendering or physical monitor-DPI behavior.

## Wrapped but unused

`SciCall_IsRangeWord` exists in `src\SciCall.h` but has no caller. See [open questions](../open-questions.md) before using it to replace delimiter scans.
2 changes: 1 addition & 1 deletion agent-trail/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The checker rejects broken/escaping links, undeclared topic folders, mismatched
| Bug fix, small feature, characterization test, focused check, or doc proposal | [Maintenance playbooks](playbooks/maintenance.md) (read only the relevant procedure) |
| Instructions, routing, adapters, skills, or the docs checker | [Review the agent docs](playbooks/docs-review.md) |
| Menus, commands, source layout, coding conventions, buffers | [Codebase and conventions](architecture/codebase-and-conventions.md) |
| Replacing home-grown `Edit.c` code with Scintilla messages | [Scintilla API usage](architecture/scintilla-api-usage.md) |
| Scintilla message replacements, zoom call-tip positioning, or Scintilla upgrades | [Scintilla API usage](architecture/scintilla-api-usage.md) |
| Build, MSBuild, CI, test scripts, Python scripting | [Windows build and test](build-and-test/windows-build-and-test.md) |
| `Edit.c` load/save, atomic save, file watching, Open/MRU dialogs | [File I/O](domain/file-io.md) |
| Any Win32 file/path call on `HPATHL` | [PathLib](domain/pathlib.md) |
Expand Down
2 changes: 2 additions & 0 deletions agent-trail/playbooks/maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Output: implemented behavior, extension points, evidence, and explicit exclusion
4. Run against unchanged production source first; record stub/integration boundaries.
5. Change the expectation only as part of the requested behavior change.

Prefer linking self-contained production helpers where practical. Test doubles must preserve observable allocation/lifecycle and return-value contracts; a more permissive double can hide a regression. The [WebTemplate runner](../../test/TestWebTemplates.ps1) links production `DynStrg.c` to exercise the real [lazy-string initialization contract](../architecture/codebase-and-conventions.md#dynamic-stringpath-buffer-lifetime).

Stop if isolation requires product refactoring or desktop interaction could disturb another user. Recommend a manual reproduction record or separately approved test seam.

Output: characterized boundary, cases, stubs, baseline outcome, and uncovered integration.
Expand Down
10 changes: 10 additions & 0 deletions readme/config/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,16 @@ Controls ESC key behavior:

Zoom tooltip display duration in milliseconds. Set to `0` to disable.

#### `ZoomTooltipPosition=0`

Selects where the temporary zoom tooltip appears:
- **0** (default): Existing upper-left placement.
- **1**: Upper-right of the editor text area, constrained to the monitor work area.
- **2**: Near the caret, if it is visible; otherwise upper-left.
- **3**: Near the mouse pointer inside the editor text area, including space beyond line endings and empty editor space. If the pointer is outside that area or its coordinates cannot be obtained, use the visible caret, then upper-left.

Caret mode is text-anchored. Mouse mode uses pixel coordinates and does not require virtual-space selection to be enabled. It offsets the tooltip from the sampled pointer, flips to the other side near right/bottom edges, and constrains placement to the editor text area and monitor work area where the tooltip fits. The pointer is sampled when the tooltip appears; the tooltip does not follow later mouse movement. Missing or unsupported values use `0`. `ZoomTooltipTimeout` still controls the display duration.

#### `WrapAroundTooltipTimeout=2000`

Search wrap-around tooltip duration in milliseconds. Set to `0` to disable.
Expand Down
5 changes: 5 additions & 0 deletions src/Config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,11 @@ void LoadSettings()

Settings2.ZoomTooltipTimeout = clampi(IniSectionGetInt(IniSecSettings2, L"ZoomTooltipTimeout", 3200), 0, 10000);

Settings2.ZoomTooltipPosition = IniSectionGetInt(IniSecSettings2, L"ZoomTooltipPosition", ZOOM_TOOLTIP_UPPER_LEFT);
if (Settings2.ZoomTooltipPosition < ZOOM_TOOLTIP_UPPER_LEFT || Settings2.ZoomTooltipPosition > ZOOM_TOOLTIP_MOUSE) {
Settings2.ZoomTooltipPosition = ZOOM_TOOLTIP_UPPER_LEFT;
}

Settings2.WrapAroundTooltipTimeout = clampi(IniSectionGetInt(IniSecSettings2, L"WrapAroundTooltipTimeout", 2000), 0, 10000);

Settings2.LargeIconScalePrecent = clampi(IniSectionGetInt(IniSecSettings2, L"LargeIconScalePrecent", 150), 100, 1000);
Expand Down
157 changes: 144 additions & 13 deletions src/Notepad3.c
Original file line number Diff line number Diff line change
Expand Up @@ -13624,6 +13624,113 @@ int NP3_GetZoomPercent()
return Globals.iZoomPercent;
}

//=============================================================================
//
// _GetZoomCallTipViewport()
//
static bool _GetZoomCallTipViewport(RECT* rcViewport)
{
if (!GetClientRect(Globals.hwndEdit, rcViewport)) {
return false;
}
rcViewport->left += SciCall_GetMarginLeft();
int const margins = SciCall_GetMargins();
for (int i = 0; i < margins; ++i) {
rcViewport->left += SciCall_GetMarginWidthN(i);
}
rcViewport->right -= SciCall_GetMarginRight();
return !IsRectEmpty(rcViewport);
}


//=============================================================================
//
// _GetZoomCallTipCaret()
//
static DocPos _GetZoomCallTipCaret(const RECT* rcViewport)
{
DocPos const pos = SciCall_GetCurrentPos();
if (!SciCall_GetLineVisible(SciCall_LineFromPosition(pos))) {
return -1;
}
POINT const pt = { (LONG)SciCall_PointXFromPosition(pos), (LONG)SciCall_PointYFromPosition(pos) };
return PtInRect(rcViewport, pt) ? pos : -1;
}


//=============================================================================
//
// _FindZoomCallTip()
//
static BOOL CALLBACK _FindZoomCallTip(HWND hwnd, LPARAM lParam)
{
if (GetWindow(hwnd, GW_OWNER) != GetAncestor(Globals.hwndEdit, GA_ROOT)) {
return TRUE;
}
WCHAR className[32] = { L'\0' };
if (!GetClassName(hwnd, className, COUNTOF(className)) || lstrcmp(className, L"CallTip") != 0) {
return TRUE;
}
// Scintilla's CTWndProc stores the editor's direct pointer in window extra bytes.
LONG_PTR const sci = (LONG_PTR)SciCall_GetDirectPointer();
if (!sci || GetWindowLongPtr(hwnd, 0) != sci) {
return TRUE;
}

*(HWND*)lParam = hwnd;
return FALSE;
}


//=============================================================================
//
// _PositionZoomCallTip()
//
static void _PositionZoomCallTip(const RECT* rcViewport, const POINT* mouse)
{
HWND hwnd = NULL;
EnumThreadWindows(GetCurrentThreadId(), _FindZoomCallTip, (LPARAM)&hwnd);

RECT rcTip;
if (!hwnd || !GetWindowRect(hwnd, &rcTip)) {
return;
}

LONG const width = rcTip.right - rcTip.left;
LONG const height = rcTip.bottom - rcTip.top;
int const gap = ScaleIntToDPI(Globals.hwndEdit, 4);
LONG x = max_l(rcViewport->left, rcViewport->right - width - gap);
LONG y = min_l(rcViewport->top + gap, max_l(rcViewport->top, rcViewport->bottom - height));
RECT rcPosition = { x, y, x + width, y + height };
if (mouse) {
SetRect(&rcPosition, mouse->x, mouse->y, mouse->x + 1, mouse->y + 1);
}
MONITORINFO mi = { sizeof(mi) };
bool const hasMonitor = GetMonitorInfo(MonitorFromRect(&rcPosition, MONITOR_DEFAULTTONEAREST), &mi);
if (mouse) {
RECT bounds = *rcViewport;
if (hasMonitor && !IntersectRect(&bounds, rcViewport, &mi.rcWork)) {
bounds = mi.rcWork;
}
x = mouse->x + gap;
y = mouse->y + gap;
if (x + width > bounds.right) {
x = mouse->x - width - gap;
}
if (y + height > bounds.bottom) {
y = mouse->y - height - gap;
}
x = max_l(bounds.left, min_l(x, bounds.right - width));
y = max_l(bounds.top, min_l(y, bounds.bottom - height));
}
if (hasMonitor) {
x = max_l(mi.rcWork.left, min_l(x, mi.rcWork.right - width));
y = max_l(mi.rcWork.top, min_l(y, mi.rcWork.bottom - height));
}
SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
}


//=============================================================================
//
// ShowZoomCallTip()
Expand All @@ -13632,23 +13739,47 @@ void ShowZoomCallTip()
{
static char chToolTip[64] = { '\0' };
int const delayClr = Settings2.ZoomTooltipTimeout;
if (delayClr >= (_MQ_TIMER_CYCLE << 3)) {

StringCchPrintfA(chToolTip, COUNTOF(chToolTip), "Zoom: %i%%", NP3_GetZoomPercent());

DocPos const iPos = SciCall_PositionFromLine(SciCall_GetFirstVisibleLine());
if (delayClr < (_MQ_TIMER_CYCLE << 3)) {
Sci_CallTipCancelEx();
return;
}

int const iXOff = SciCall_GetXOffset();
StringCchPrintfA(chToolTip, COUNTOF(chToolTip), "Zoom: %i%%", NP3_GetZoomPercent());

RECT rcViewport;
bool const hasViewport = Settings2.ZoomTooltipPosition != ZOOM_TOOLTIP_UPPER_LEFT && _GetZoomCallTipViewport(&rcViewport);
POINT origin = { 0, 0 };
bool const hasScreenViewport = hasViewport && ClientToScreen(Globals.hwndEdit, &origin);
POINT mouse = { 0, 0 };
bool const atMouse = hasScreenViewport && Settings2.ZoomTooltipPosition == ZOOM_TOOLTIP_MOUSE
&& GetCursorPos(&mouse) && ScreenToClient(Globals.hwndEdit, &mouse) && PtInRect(&rcViewport, mouse);
DocPos pos = -1;
if (atMouse) {
pos = SciCall_GetCurrentPos(); // Only used to create and measure the popup.
} else if (hasViewport && (Settings2.ZoomTooltipPosition == ZOOM_TOOLTIP_CARET || Settings2.ZoomTooltipPosition == ZOOM_TOOLTIP_MOUSE)) {
pos = _GetZoomCallTipCaret(&rcViewport);
}
bool const useLegacyAnchor = pos < 0;
int const iXOff = SciCall_GetXOffset();
if (useLegacyAnchor) {
pos = SciCall_PositionFromLine(SciCall_GetFirstVisibleLine());
SciCall_SetXOffset(-4); // move away from margin

SciCall_CallTipSetPosition(true); // show above
SciCall_CallTipShow(iPos, chToolTip);
}
SciCall_CallTipSetPosition(useLegacyAnchor);
SciCall_CallTipShow(pos, chToolTip);
if (useLegacyAnchor) {
SciCall_SetXOffset(iXOff);
_DelayClearCallTip(delayClr);
} else {
Sci_CallTipCancelEx();
}

if (hasScreenViewport && (Settings2.ZoomTooltipPosition == ZOOM_TOOLTIP_UPPER_RIGHT || atMouse)) {
OffsetRect(&rcViewport, origin.x, origin.y);
if (atMouse) {
mouse.x += origin.x;
mouse.y += origin.y;
}
_PositionZoomCallTip(&rcViewport, atMouse ? &mouse : NULL);
}
_DelayClearCallTip(delayClr);
}


Expand Down
8 changes: 8 additions & 0 deletions src/TypeDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ typedef enum FR_STATES { FND_NOP = 0, NXT_NOT_FND, NXT_FND, NXT_WRP_FND, PRV_NOT
typedef enum FR_UPD_MODES { FRMOD_IGNORE = 0, FRMOD_NORM, FRMOD_WRAPED } FR_UPD_MODES;
typedef enum WIN_DISPL_MODE { WINDSPMOD_AUTO = 0, WINDSPMOD_DARK, WINDSPMOD_LIGHT } WIN_DISPL_MODE;

typedef enum ZOOM_TOOLTIP_POSITION {
ZOOM_TOOLTIP_UPPER_LEFT = 0,
ZOOM_TOOLTIP_UPPER_RIGHT = 1,
ZOOM_TOOLTIP_CARET = 2,
ZOOM_TOOLTIP_MOUSE = 3
} ZOOM_TOOLTIP_POSITION;

//==== Statusbar ==============================================================

typedef WCHAR prefix_t[MICRO_BUFFER];
Expand Down Expand Up @@ -834,6 +841,7 @@ typedef struct SETTINGS2_T {
bool DiscardOnClosingUntitledPasteBoard;
int ExitOnESCSkipLevel;
int ZoomTooltipTimeout;
int ZoomTooltipPosition;
int WrapAroundTooltipTimeout;
int LargeIconScalePrecent;
int DarkModeHiglightContrast;
Expand Down
Loading