diff --git a/README.md b/README.md
index c588354..e2494d7 100644
--- a/README.md
+++ b/README.md
@@ -89,7 +89,9 @@ so even multi-megabyte docs stay smooth). Pick **Language → Markdown** on any
###
Reading mode
**Toggle Reading Mode** and the editor area itself becomes the rendered document, at the exact spot you were
-reading. Toggle again, or **double-click any paragraph**, to jump back into the source at that line. Turn on
+reading. Toggle again to jump back into the source. Double-clicking a paragraph keeps you in reading mode and puts the
+source cursor on that line, so toggling off lands there. In the preview panel, double-click jumps straight to the
+source line. Turn on
*Open Markdown in Reading Mode* and `.md` files open as documents, not code.
@@ -263,6 +265,8 @@ Windows 11; on Windows 10 it comes with Edge).
##
Using it
Everything lives under **Plugins → MarkdownReader**. Bind any of these to keys in *Settings → Shortcut Mapper*.
+The toolbar also has separate buttons for **Toggle Reading Mode** and **Toggle Preview Panel**.
+Both modes can be active at the same time.
| Command | What it does |
|---|---|
@@ -375,7 +379,7 @@ every push and pull request.
- [x] CI on GitHub Actions: ARM64, x64 and x86 builds plus the web and native tests (thanks to
[chcg](https://github.com/chcg))
- [ ] Hands-on verification of export, print, links and shortcuts → **v0.2**
-- [ ] Toolbar buttons, a settings dialog and an x86 release
+- [ ] A settings dialog and an x86 release
- [ ] Native Markdown syntax highlighting with its own *Language* menu entry
- [ ] Ideas welcome: open an issue!
diff --git a/src/MarkdownReader.rc b/src/MarkdownReader.rc
index cecab92..e3cb1dc 100644
--- a/src/MarkdownReader.rc
+++ b/src/MarkdownReader.rc
@@ -3,6 +3,13 @@
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+IDB_READING_MODE BITMAP "reading-mode.bmp"
+IDI_READING_MODE ICON "reading-mode.ico"
+IDI_READING_MODE_DARK ICON "reading-mode-dark.ico"
+IDB_PREVIEW_PANEL BITMAP "preview-panel.bmp"
+IDI_PREVIEW_PANEL ICON "preview-panel.ico"
+IDI_PREVIEW_PANEL_DARK ICON "preview-panel-dark.ico"
+
VS_VERSION_INFO VERSIONINFO
FILEVERSION MDR_VERSION_MAJOR, MDR_VERSION_MINOR, MDR_VERSION_PATCH, MDR_VERSION_BUILD
PRODUCTVERSION MDR_VERSION_MAJOR, MDR_VERSION_MINOR, MDR_VERSION_PATCH, MDR_VERSION_BUILD
diff --git a/src/NppApi.cpp b/src/NppApi.cpp
index d4aa6be..b1e1988 100644
--- a/src/NppApi.cpp
+++ b/src/NppApi.cpp
@@ -133,4 +133,10 @@ void GotoDocLine(HWND sci, int line) {
ScrollToDocLine(sci, line > 3 ? line - 3 : 0);
}
+void PlaceCaretAtDocLine(HWND sci, int line) {
+ Sci(sci, SCI_ENSUREVISIBLE, static_cast(line));
+ const auto position = Sci(sci, SCI_POSITIONFROMLINE, static_cast(line));
+ if (position >= 0) Sci(sci, SCI_SETEMPTYSELECTION, static_cast(position)); // does not scroll
+}
+
} // namespace mdr::npp
diff --git a/src/NppApi.h b/src/NppApi.h
index 0a295d5..7694e99 100644
--- a/src/NppApi.h
+++ b/src/NppApi.h
@@ -37,5 +37,6 @@ size_t DocumentLength(HWND sci);
int FirstVisibleDocLine(HWND sci);
void ScrollToDocLine(HWND sci, int line);
void GotoDocLine(HWND sci, int line);
+void PlaceCaretAtDocLine(HWND sci, int line); // moves the caret without scrolling
} // namespace mdr::npp
diff --git a/src/Plugin.cpp b/src/Plugin.cpp
index 0309054..fb9a962 100644
--- a/src/Plugin.cpp
+++ b/src/Plugin.cpp
@@ -216,6 +216,23 @@ void Plugin::OnNotification(SCNotification* notification) {
const auto& header = notification->nmhdr;
if (header.hwndFrom == npp::Window()) {
switch (header.code) {
+ case NPPN_TBMODIFICATION: {
+ // Notepad++ retains the image handles for the lifetime of the toolbar.
+ static const wil::unique_hbitmap readingBitmap(::LoadBitmapW(module_, MAKEINTRESOURCEW(IDB_READING_MODE)));
+ static const wil::unique_hbitmap panelBitmap(::LoadBitmapW(module_, MAKEINTRESOURCEW(IDB_PREVIEW_PANEL)));
+ const auto addButton = [this](Command command, HBITMAP bitmap, int icon, int darkIcon) {
+ toolbarIconsWithDarkMode icons{
+ bitmap,
+ ::LoadIconW(module_, MAKEINTRESOURCEW(icon)),
+ ::LoadIconW(module_, MAKEINTRESOURCEW(darkIcon)),
+ };
+ ::SendMessageW(npp::Window(), NPPM_ADDTOOLBARICON_FORDARKMODE, commands_[command]._cmdID,
+ reinterpret_cast(&icons));
+ };
+ addButton(kCmdReading, readingBitmap.get(), IDI_READING_MODE, IDI_READING_MODE_DARK);
+ addButton(kCmdPanel, panelBitmap.get(), IDI_PREVIEW_PANEL, IDI_PREVIEW_PANEL_DARK);
+ break;
+ }
case NPPN_READY: OnReady(); break;
case NPPN_SHUTDOWN: OnShutdown(); break;
case NPPN_BUFFERACTIVATED:
@@ -289,6 +306,9 @@ void Plugin::OnActiveBufferChanged() {
}
if (!currentIsMarkdown) state.reading = false;
+ auto& currentReading = reading_[currentView];
+ const bool wasReadingCurrent = currentReading.overlay.IsActive() && currentReading.bufferId == current;
+
// Both views: moving a document between views changes the other view too.
for (int view = 0; view < 2; ++view) {
const UINT_PTR id = view == currentView ? current : npp::BufferInView(view);
@@ -297,6 +317,14 @@ void Plugin::OnActiveBufferChanged() {
UpdateReadingView(view, id, active);
}
+ // Reloading a file from disk detaches the editor from the document, so no
+ // SCN_MODIFIED arrives; Notepad++ only re-activates the buffer afterwards.
+ // A reading view that kept its document renders it again to catch that.
+ if (wasReadingCurrent && currentReading.overlay.IsActive() && currentReading.host &&
+ currentReading.host->IsPageReady()) {
+ RenderTo(*currentReading.host, current, npp::ScintillaForView(currentView), false);
+ }
+
if (currentIsMarkdown && !state.reading && settings_.autoOpenPanel && !panelDismissed_ && !PanelOpen()) {
ShowPanel(true);
}
@@ -703,14 +731,14 @@ void Plugin::OnPageMessage(WebViewHost& host, PageMessage message) {
break;
case PageMessage::Type::GotoLine:
- Defer([this, view, line = message.line] {
- const int targetView = view < 0 ? npp::CurrentView() : view;
+ Defer([view, line = message.line] {
if (view >= 0) {
- buffers_[reading_[view].bufferId].reading = false;
- UpdateReadingView(view, reading_[view].bufferId, false);
- UpdateMenuChecks();
+ // Reading mode stays on until it is toggled off. The hidden
+ // editor's caret moves to the line, so toggling off lands there.
+ npp::PlaceCaretAtDocLine(npp::ScintillaForView(view), line);
+ return;
}
- const HWND scintilla = npp::ScintillaForView(targetView);
+ const HWND scintilla = npp::CurrentScintilla();
npp::GotoDocLine(scintilla, line);
::SetFocus(scintilla);
});
diff --git a/src/preview-panel-dark.ico b/src/preview-panel-dark.ico
new file mode 100644
index 0000000..c994b11
Binary files /dev/null and b/src/preview-panel-dark.ico differ
diff --git a/src/preview-panel.bmp b/src/preview-panel.bmp
new file mode 100644
index 0000000..c8b5b39
Binary files /dev/null and b/src/preview-panel.bmp differ
diff --git a/src/preview-panel.ico b/src/preview-panel.ico
new file mode 100644
index 0000000..5e45550
Binary files /dev/null and b/src/preview-panel.ico differ
diff --git a/src/reading-mode-dark.ico b/src/reading-mode-dark.ico
new file mode 100644
index 0000000..5e63021
Binary files /dev/null and b/src/reading-mode-dark.ico differ
diff --git a/src/reading-mode.bmp b/src/reading-mode.bmp
new file mode 100644
index 0000000..3490efd
Binary files /dev/null and b/src/reading-mode.bmp differ
diff --git a/src/reading-mode.ico b/src/reading-mode.ico
new file mode 100644
index 0000000..23630db
Binary files /dev/null and b/src/reading-mode.ico differ
diff --git a/src/resource.h b/src/resource.h
index 267327a..38105c9 100644
--- a/src/resource.h
+++ b/src/resource.h
@@ -9,3 +9,9 @@
#define MDR_VERSION_WSTRING L"0.1.0"
#define IDD_PREVIEW_PANEL 100
+#define IDB_READING_MODE 101
+#define IDI_READING_MODE 102
+#define IDI_READING_MODE_DARK 103
+#define IDB_PREVIEW_PANEL 104
+#define IDI_PREVIEW_PANEL 105
+#define IDI_PREVIEW_PANEL_DARK 106