6
$\begingroup$

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.

$\endgroup$
8
  • 1
    $\begingroup$ Workaround ? : StringReplace[ToString[Unevaluated[WORD1 WORD2 WORD3]], " " -> ""] $\endgroup$
    – SquareOne
    Sep 2 '20 at 7:13
  • $\begingroup$ 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 "" ? $\endgroup$
    – SquareOne
    Sep 2 '20 at 7:28
  • $\begingroup$ 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. $\endgroup$ Sep 2 '20 at 7:58
  • 3
    $\begingroup$ 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, $\endgroup$
    – SquareOne
    Sep 2 '20 at 9:45
  • 1
    $\begingroup$ I believe the behavior is the result of this: reference.wolfram.com/language/ref/frontendobject/… -- I don't know if it can be changed. $\endgroup$
    – Michael E2
    Sep 2 '20 at 13:30
3
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.