6

We can select parts of code or text by repeated clicks like so:

1enter image description here

2enter image description here

3enter image description here

4enter image description here

5enter image description here

But it seems like Mathematica skips one level. Between image 2 and 3 there should be an intermediate level of selected code that would highlight only WORD1 WORD2 WORD3 not with quotation marks like we can see on image 3.

Is there some way I can tell Mathematica to select text by clicking inside quotation marks properly?

This drives me crazy I have to copy lots of texts manually from different sources to the same place in code between quotation marks. But I have to first click right of the first quotation mark then hold the mouse button and move mouse to left of the second quotation mark release button and only then I can pres CTRL+V to paste text. Or I can triple click then type SHIFT + " then press CTRL+V and finally press SHIFT + " again.

If the selection was done properly I would do only triple click and press CTRL+V and the new text would appear inside quotation marks.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
azerbajdzan
  • 15,863
  • 1
  • 16
  • 48
  • 1
    Workaround ? : StringReplace[ToString[Unevaluated[WORD1 WORD2 WORD3]], " " -> ""] – SquareOne Sep 02 '20 at 07:13
  • By the way, something is not clear for me : do you want to insert new text and new code or replace some existing code and text in the notebook ? If you want only to insert new text and code you could just start from StringReplace["", " " -> ""] then insert your string inside the first "" ? – SquareOne Sep 02 '20 at 07:28
  • Nice workaroud! I will use it. I have the same code all the time I just need to paste text manually inside"", then evaluate the code, then paste a new text in place of the previous one and so on... if you have to press Shift+" Ctrl+V Shift+" with left hand (while using mouse in right hand) about hundred times in a row you will understand what I mean. Ctrl+V lies on the left of the keyboard and Shift+" on right of the keyboard. Unfortunately the pasting can not be done automatically it needs to be done manually. – azerbajdzan Sep 02 '20 at 07:58
  • @SquareOne: The workaroud only works when there is no special characters like /*-+?.<> in the copied text. Fortunately my texts only consist of letters A..Z and space. – azerbajdzan Sep 02 '20 at 08:11
  • 3
    OK, first I think there is certainly an (easy) automated solution that would work for your main problem, copying and pasting a hundred times seems really the bad way ... You can post another question and explain the workflow. Now, if you still want to do the replacement by hand and have some special characters in your string, here is another workaround : instead of "WORD1 WORD2 WORD3" write StringTake["(WORD1 WORD2 WORD3)", {2, -2}] : the repeated clicks will allow to select only what is between the parenthesis, – SquareOne Sep 02 '20 at 09:45
  • This workaround is perfect!!! Well it can not be done automatically. I have to read some searched articles on the web and then parts of the text that are of my interest copy and paste into the code. But it would be tedious (if not impossible) to write a code to make Mathematica decide whether the particular part of text would be interesting to me or not...my criteria are very complex and it needs understanding of the text. On the other had if it was some structured data like table or so and I needed to paste each line of the table to Mathematica then I know how to do it. – azerbajdzan Sep 02 '20 at 10:40
  • Why don't you 1/ Copy/Paste all the different texts into a single file as a single list of strings ({"text1...", "text2...", ...}), 2/ Read the file and this list into Mathematica 3/ Apply your function to each of the strings in the list (using Map). You'll save at least half of the time compared to now. By the way if you use Unix/lLinux like OS, maybe a program utility like sed would fit your needs to parse and transform the text. – SquareOne Sep 02 '20 at 12:59
  • 1
    I believe the behavior is the result of this: http://reference.wolfram.com/language/ref/frontendobject/ExpandSelection.html -- I don't know if it can be changed. – Michael E2 Sep 02 '20 at 13:30

1 Answers1

3

You can automate it with e.g. my DevTools`' NotebookActions.

Just follow those steps: Add spaces to Mathematica comment delimiters?

But use item:

<|
  "Label"    -> "Copy string content"
, "ShortKey" -> "c"
, "Action"   :> ( CopyToClipboard @ If[
    StringQ@# && StringMatchQ[#,"\""~~___~~"\""]
  , StringTake[#,{2,-2}]
  , Beep[]
  ]& @ CurrentValue[InputNotebook[],"SelectionData"])
|>

seems to work:

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740