Community
    • Login

    Control symbols now inserted on macro

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    27 Posts 6 Posters 6.8k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • EkopalypseE Offline
      Ekopalypse @PeterJones
      last edited by

      @PeterJones

      agreed - very strange. I’m wondering if XP and Wine share the same code
      for the needed functionality is this case.
      Would make some sense. Maybe some older unicode library or different than W7 and W10.
      I thought about it for some time now, but I don’t see
      how to start on this to track down the bug.

      andrecool-68A 1 Reply Last reply Reply Quote 2
      • andrecool-68A Offline
        andrecool-68 @Ekopalypse
        last edited by

        @Ekopalypse There has been a problem with the definition of encodings for a very long time, sometimes it is solved but partially))
        And then a new surprise appears with encodings))

        EkopalypseE 1 Reply Last reply Reply Quote 1
        • EkopalypseE Offline
          Ekopalypse @andrecool-68
          last edited by

          @andrecool-68 said in Control symbols now inserted on macro:

          There has been a problem with the definition of encodings for a very long time

          :-) I agree but it has reached a new level I would say. :-(
          I can live with limitation if I understand why their are,
          but fishing in the dark for understanding drives me mad.

          andrecool-68A 1 Reply Last reply Reply Quote 2
          • andrecool-68A Offline
            andrecool-68 @Ekopalypse
            last edited by

            @Ekopalypse This is no longer fishing … it’s sex with a concrete wall))

            EkopalypseE 1 Reply Last reply Reply Quote 1
            • EkopalypseE Offline
              Ekopalypse @andrecool-68
              last edited by

              @andrecool-68
              :-D ouch

              1 Reply Last reply Reply Quote 1
              • Alan KilbornA Offline
                Alan Kilborn
                last edited by Alan Kilborn

                I finally was able to get this problem to replicate under debugger control (what I was missing before was that my file was coming up with ANSI encoding preselected – and I didn’t notice that; now when the debugger starts up I go in to the N++ Encoding menu and change it to UTF-8).

                Here’s the problem:

                void recordedMacroStep::PlayBack(Window* pNotepad, ScintillaEditView *pEditView)
                {
                	if (_macroType == mtMenuCommand)
                	{
                		::SendMessage(pNotepad->getHSelf(), WM_COMMAND, _wParameter, 0);
                	}
                	else
                	{
                		// Ensure it's macroable message before send it
                		if (!isMacroable())
                			return;
                
                		if (_macroType == mtUseSParameter) 
                		{
                			char ansiBuffer[3];
                			::WideCharToMultiByte(static_cast<UINT>(pEditView->execute(SCI_GETCODEPAGE)), 0, _sParameter.c_str(), -1, ansiBuffer, 3, NULL, NULL);
                

                The ::WideCharToMultiByte call returns 0 – indicating failure – and then a call to GetLastError returns 122 which is ERROR_INSUFFICIENT_BUFFER.

                Indeed, the size of ansiBuffer, i.e., 3, is one too small for this case.

                Changing it to 4 cures the problem for the UTF-8 files:

                char ansiBuffer[4];
                ::WideCharToMultiByte(static_cast<UINT>(pEditView->execute(SCI_GETCODEPAGE)), 0, _sParameter.c_str(), -1, ansiBuffer, 4, NULL, NULL);
                
                1 Reply Last reply Reply Quote 3
                • PeterJonesP Offline
                  PeterJones
                  last edited by

                  @Alan-Kilborn said in Control symbols now inserted on macro:

                  recordedMacroStep::PlayBack
                  … ansiBuffer[4];

                  That makes some sense. At first I was wondering what change prompted that to start failing, and the GitHub blame shows those two lines haven’t been changed in 3-4 years. But really, if Scintilla changed the way it’s doing things, maybe the _sParameter.c_str() now has a 4byte char rather than a 3byte char, or something.

                  Alternately, MS Docs: WideCharToMultiByte shows that sending cbMultiByte (the 3 or 4 in the last arg before the NULLs) as a 0 will have it return the width needed, so wouldn’t it be more future proof to use:

                  int ansiBufferLength = ::WideCharToMultiByte(static_cast<UINT>(pEditView->execute(SCI_GETCODEPAGE)), 0, _sParameter.c_str(), -1, ansiBuffer, 0, NULL, NULL);  // grab needed ansiBuffer length
                  ::WideCharToMultiByte(static_cast<UINT>(pEditView->execute(SCI_GETCODEPAGE)), 0, _sParameter.c_str(), -1, ansiBuffer, ansiBufferLength, NULL, NULL);
                  

                  (though you’d need to either re-dim ansiBuffer, or make sure it’s always got enough room)

                  1 Reply Last reply Reply Quote 3

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors