Giter Site home page Giter Site logo

Comments (2)

vinsworldcom avatar vinsworldcom commented on May 27, 2024 4

Yes, me too. Notepad++ 7.8.6 64-bit. Looking at the code:

NppMarkdownPanel\NppMarkdownPanel\MarkdownPanelController.cs
49: public void OnNotification(ScNotification notification)

traps some events, in fact, you trap the right event:

NppMarkdownPanel\NppMarkdownPanel\MarkdownPanelController.cs

66:  else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED)

But the checking for SC_MOD_INSERTTEXT or SC_MOD_DELETETEXT seems to always turn up false as it never gets to

74:  RenderMarkdown();

I commented out:

NppMarkdownPanel\NppMarkdownPanel\MarkdownPanelController.cs

68:	                    // bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0;
69:	                    // bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0;
70:	                    // // Any modifications made ?
71:	                    // if (isInsert || isDelete)
72:	                    // {
73:	                        lastTickCount = Environment.TickCount;
74:	                        RenderMarkdown();
75:	                    // }

and it started automatically refreshing as I typed!

I also added a bit of scrolling buffer so that the Markdown preview doesn't sync it's top line with the N++ buffer with "Synchronize viewer with caret position" enabled. Basically, I just adjust down 10 lines, but it's configurable in the .INI file (maybe you want to expose that in your settings dialogue?).

C# is not my language; I was very lucky this compiled with no errors on VS2017. The following is a patch including my only changes:

--------

diff --git a/NppMarkdownPanel/MarkdownPanelController.cs b/NppMarkdownPanel/MarkdownPanelController.cs
index fe87cf5..30ef5d9 100644
--- a/NppMarkdownPanel/MarkdownPanelController.cs
+++ b/NppMarkdownPanel/MarkdownPanelController.cs
@@ -35,6 +35,7 @@ namespace NppMarkdownPanel
         private int lastCaretPosition;
         private string iniFilePath;
         private bool syncViewWithCaretPosition;
+        private int ScrollBuffer;

         public MarkdownPanelController()
         {
@@ -55,7 +56,7 @@ namespace NppMarkdownPanel
                     if (syncViewWithCaretPosition && lastCaretPosition != scintillaGateway.GetCurrentPos().Value)
                     {
                         lastCaretPosition = scintillaGateway.GetCurrentPos().Value;
-                        ScrollToElementAtLineNo(scintillaGateway.GetCurrentLineNumber());
+                        ScrollToElementAtLineNo(scintillaGateway.GetCurrentLineNumber() - ScrollBuffer);
                     }
                 }
                 else
@@ -65,14 +66,14 @@ namespace NppMarkdownPanel
                 }
                 else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED)
                 {
-                    bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0;
-                    bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0;
-                    // Any modifications made ?
-                    if (isInsert || isDelete)
-                    {
+                    // bool isInsert = (notification.ModificationType & (uint)SciMsg.SC_MOD_INSERTTEXT) != 0;
+                    // bool isDelete = (notification.ModificationType & (uint)SciMsg.SC_MOD_DELETETEXT) != 0;
+                    // // Any modifications made ?
+                    // if (isInsert || isDelete)
+                    // {
                         lastTickCount = Environment.TickCount;
                         RenderMarkdown();
-                    }
+                    // }
                 }
             }
         }
@@ -117,7 +118,8 @@ namespace NppMarkdownPanel
             SetIniFilePath();
             syncViewWithCaretPosition = (Win32.GetPrivateProfileInt("Options", "SyncViewWithCaretPosition", 0, iniFilePath) != 0);
             markdownPreviewForm.CssFileName = Win32.ReadIniValue("Options", "CssFileName", iniFilePath, "style.css");
-            markdownPreviewForm.ZoomLevel = Win32.GetPrivateProfileInt("Options", "ZoomLevel", 130, iniFilePath);
+            markdownPreviewForm.ZoomLevel = Win32.GetPrivateProfileInt("Options", "ZoomLevel", 100, iniFilePath);
+            ScrollBuffer = Win32.GetPrivateProfileInt("Options", "ScrollBuffer", 10, iniFilePath);
             PluginBase.SetCommand(0, "About", ShowAboutDialog, new ShortcutKey(false, false, false, Keys.None));
             PluginBase.SetCommand(1, "Toggle Markdown Panel", TogglePanelVisible);
             PluginBase.SetCommand(2, "Synchronize viewer with caret position", SyncViewWithCaret, syncViewWithCaretPosition);
@@ -169,6 +171,7 @@ namespace NppMarkdownPanel
         public void PluginCleanUp()
         {
             Win32.WritePrivateProfileString("Options", "SyncViewWithCaretPosition", syncViewWithCaretPosition ? "1" : "0", iniFilePath);
+            Win32.WriteIniValue("Options", "ScrollBuffer", ScrollBuffer.ToString(), iniFilePath);
             SaveSettings();
         }

--------

Cheers.

from nppmarkdownpanel.

mohzy83 avatar mohzy83 commented on May 27, 2024

this is fixed in release 0.6.1

from nppmarkdownpanel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.