• Login
Community
  • Login

How to replace selected text of a selected rectangle?

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
4 Posts 2 Posters 1.7k Views
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.
  • O
    Ollo Heß
    last edited by Nov 20, 2018, 1:24 PM

    Hey,
    I wrote a plugin that should format some selected text.
    If the selection is a complete line I can use SCI_REPLACESEL to insert the modified text.

    What do I have to do, if I want to replace the text of a selected rectangle?

    Thanks in advance
    Ollo

    S 1 Reply Last reply Nov 20, 2018, 6:49 PM Reply Quote 0
    • S
      Scott Sumner @Ollo Heß
      last edited by Nov 20, 2018, 6:49 PM

      @Ollo-Heß

      You have to take a more manual approach to it using other (“lower-level”) SCI_ functions for getting selections and replacing text. If that isn’t enough of a help for you, post again requesting more details.

      1 Reply Last reply Reply Quote 0
      • O
        Ollo Heß
        last edited by Nov 21, 2018, 1:02 PM

        Hey @scott-sumner,
        thanks for your answer, but unfortunately it doesn’t help me.

        Before I posted my question here, I took a look at the Scintilla Documentation.

        I wrote a plugin library that reads the selected text -> SCI_GETSELTEXT
        This works fine, with all selection kinds.

        If I select a rectagle, e. g. a column, I get a multiline text with linebreaks.

        Now, my formatting function modifies this text.

        After this modification I need to replace the selected text of the document.
        I tried SCI_REPLACESEL, but this inserts the text with the linebreaks at the fist position of the selection.
        So, not the selected rectangle will be replaced.

        How can I replace the text of a selected rectangle?

        S 1 Reply Last reply Nov 21, 2018, 3:23 PM Reply Quote 0
        • S
          Scott Sumner @Ollo Heß
          last edited by Nov 21, 2018, 3:23 PM

          @Ollo-Heß

          I understand the desire for it to be simple for the rectangular column selection case, but it is important that you understand why it is not so, and thus why there is no simple 2-step get-selection and replace-selection for this.

          Let me first ask you some questions about what you are doing:

          • Does the initially selected rectangular block ever have any virtual space in it?
          • Are all of the lines/rows in the rectangular block you are replacing with of the same length (same number of columns for each line; note that it is fine if this is different from the number of columns in the initial selection)?
          • Does the rectangular block you are replacing with always have the same number of lines/rows as the initially selected rectangular block?

          [Maybe these questions will get you thinking along the lines of why this can be a difficult thing to do…]

          If the answers are “no”/“yes”/“yes” then the situation is “fairly” simple, and I can describes some possible ways to implement (but let’s have those answers first). We can of course discuss the cases where the answers aren’t “no”/“yes”/“yes”, but the complexity increases. :-)

          1 Reply Last reply Reply Quote 1
          1 out of 4
          • First post
            1/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors