Markdown shortcut - needs work

98 views
Skip to first unread message

Steve Garman

unread,
Jul 27, 2023, 1:15:50 PM7/27/23
to DroidScript
/*
Creating some Markdown by highlighting text and pressing a button
Could in theory be useful for Discord if completed

I wrote this tiny app while waiting for my wife
to have some scans at hospital
It has no refinement at all
The sizes of everything are only designed to fit phone and I just use the bottom of an oversized scroller as a swipe handle

It works for me although it does not save me much time

I anyone feels like expanding it (and probably fixing) it is very welcome to

In case it's not obvious, it's a native app
*/

var testText = "Hello folks and what about the workers"
function OnStart()
{
   lay = app.CreateLayout("linear", "Center, FillXY")
   txe = app.AddTextEdit( lay,testText,0.9,0.5 )
   txe.SetBackColor( "#44000044" )
   app.AddLayout(lay)
   scrol = app.AddScroller( lay,1,0.15 )
   lay2 = app.CreateLayout( "Linear","Left,horizontal")
   scrol.SetBackColor( "#44004400" )
   scrol.AddChild( lay2 )
   
    makeButton("big header%# % #")
    makeButton("medium header%## % ##")
    makeButton("small header%### % ###")
    makeButton("italic%*%*")
    makeButton("bold%**%**")
    makeButton("bold+italic%***%***")
    makeButton("underline%__%__")
    makeButton("underline+italic%__*%*__ ")
    makeButton("underline+bold+italic%__***%***__")
    makeButton("strikethough%~~%~~")
}

function makeButton( obj )
{
  var detail = obj.split("%")
  var lab= detail[0],
     pre=detail[1],
     post=detail[2]
   //alert(lab)
  var btn = app.CreateButton( lab )
  btn.data.pre = pre
  btn.data.post= post
  lay2.AddChild( btn )
  btn.SetOnTouch( btn_OnTouch )
 
}

function btn_OnTouch(btn)
{
 
 var dat = (app.eventSource).data
 var txtin = txe.GetSelectedText()
 var start= txe.GetSelectionStart()
 var end = txe.GetSelectionEnd()
 outp = dat.pre + txtin + dat.post
 txe.ReplaceText( outp,start,end )
}

Dave

unread,
Jul 29, 2023, 6:07:07 AM7/29/23
to DroidScript
Hi Steve,  

This type of feature could be added to DS V3 as a device editor extension.  I'm changing the main device menu in V3 so that it can show context related menu items when the DS code editor is visible (ie. a project is open).  In theory you could add all sorts of code and project helper tools this way.

These menus can be modified by simply including an appropriate JS script in the DroidScript/Extensions folder.  For example I'm working on a DroidScript/Extensions/Firebase/* extension at the moment which will allow you to publish web apps to Firebase :)

Steve Garman

unread,
Jul 29, 2023, 6:21:03 AM7/29/23
to DroidScript
In that case I'll probably rewrite it to use a spinner or ui drop-down instead 

Steve Garman

unread,
Jul 29, 2023, 6:28:00 AM7/29/23
to DroidScript
The web apps to firebase extension is a marvelous idea
Reply all
Reply to author
Forward
0 new messages