Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
Started "at"
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Nov 27, 2020
1 parent f5dd2d1 commit 742e004
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/src/controls/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Page = React.memo(({ control }) => {

// stack props
const stackProps = {
verticalFill: true,
verticalFill: control.verticalFill ? control.verticalFill : false,
horizontalAlign: control.horizontalalign ? control.horizontalalign : "start",
verticalAlign: control.verticalalign ? control.verticalalign : "start",
gap: control.gap ? control.gap : 10,
Expand Down
11 changes: 11 additions & 0 deletions internal/page/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -86,6 +87,10 @@ func add(session *Session, cmd command.Command) (result string, err error) {

// parent ID
topParentID := cmd.Attrs["to"]
topParentAt := -1
if ta, err := strconv.Atoi(cmd.Attrs["at"]); err == nil {
topParentAt = ta
}

if topParentID == "" {
topParentID = getPageID()
Expand Down Expand Up @@ -133,6 +138,7 @@ func add(session *Session, cmd command.Command) (result string, err error) {
controlType := batchItem.Command.Values[0]

parentID := ""
parentAt := -1

// find nearest parentID
for pi := i - 1; pi >= 0; pi-- {
Expand All @@ -145,6 +151,7 @@ func add(session *Session, cmd command.Command) (result string, err error) {
// parent wasn't found - use the topmost one
if parentID == "" {
parentID = topParentID
parentAt = topParentAt
}

// control ID
Expand All @@ -159,6 +166,10 @@ func add(session *Session, cmd command.Command) (result string, err error) {

batchItem.Control = NewControl(controlType, parentID, id)

if parentAt != -1 {
batchItem.Control.SetAttr("at", parentAt)
}

for k, v := range batchItem.Command.Attrs {
if !IsSystemAttr(k) {
batchItem.Control.SetAttr(k, v)
Expand Down
4 changes: 2 additions & 2 deletions tests/test-add-command.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ try {
# row
# button id=b1"

pglet_send "add
pglet_send "add to=page at=0
stack width=600px horizontalAlign=stretch
textbox id=fullName value='someone' label=Name placeholder='Your name, please' description='That\'s your name'
textbox id=bio label='Bio' description='A few words about yourself' value='Line1\nLine2' multiline=true
stack id=buttons horizontal=true
stack id=buttons horizontal=true
button id=submit text=Submit primary=yes event=btn_event
button id=cancel event=btn_event2"

Expand Down

0 comments on commit 742e004

Please sign in to comment.