Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.4K Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Get the current line within an InputField?

I'd like to write a basic text editor as part of a small utility app. I haven't been able to work out how to do automatic indentation when starting a new line.

What I'm ultimately trying to do is make a small tool for querying ElasticSearch by hand. The version of ES I'm stuck with only accepts JSON queries, which are painful to hand-write. YAML is pleasant to hand-write, and lends itself well to conversion into JSON. I'm using this YAML importer.

Code for the editor:

Grid[{
  {EventHandler[
    InputField[Dynamic[x], String, FieldSize -> {40, 10}, 
     ContinuousAction -> True],
    {"ReturnKeyDown" :> Paste["\n"],
     {"KeyDown", "\t"} :> Paste["  "]}]},
  {Dynamic[ExportString[ImportString[x, "YAML"], "JSON"]]}
  }]

When you press return, I would like to insert the new line and the same number of leading spaces that the previous line had. Is there an easy way to get the current line number within the InputField?

Thanks,

-Daniel

POSTED BY: Daniel Cox
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard