Search Unity

Question Caret position in EditorGUILayout.TextArea

Discussion in 'UI Toolkit' started by popochv, Jan 28, 2023.

  1. popochv

    popochv

    Joined:
    Sep 2, 2018
    Posts:
    5
    Okay, I have searched around many API and threads, but everyone talks about a caret position in TMP or normal? TextField.

    What I would like to know is the way to get the position of a caret in EditorGUILayout TextArea (or TextField).

    The reason why I want this is I am trying to design a text editor in an editor window.
    Like the TMP Inputfield, but a little more advance from that, a user can select specific texts by dragging them and click a button to change its style (e.g., bold, italic, add indent).

    Is there a way to know the caret position in an editor window?

    We can select some of the texts by dragging them to change without a problem(e.g, TMP.InputField).
    So I presume there is codes functioning to know a caret position to edit.
     
  2. magicbananna

    magicbananna

    Joined:
    May 9, 2013
    Posts:
    22
    I have basically the same issue. I have scripting editor that the user can edit their code within the unity editor. It works great so far with runtime compilation and saving. Im looking at having predefined code blocks that the user can insert to avoid having to manually type OnTriggerEnter() etc etc. The best i can come up with is to use the systemcopybuffer in utility and then paste at the caret. But this is buggy.
     
  3. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    479
    Hey, you might have more answers for this in the IMGUI forums.