id 'tab' for current tabid (#891)

This commit is contained in:
Mike Sawka 2024-09-26 23:49:35 -07:00 committed by GitHub
parent 5d8fa2e8d9
commit 52cb36bc37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -112,7 +112,7 @@ func setTermHtmlMode() {
var oidRe = regexp.MustCompile(`^[0-9a-f]{8}$`) var oidRe = regexp.MustCompile(`^[0-9a-f]{8}$`)
func validateEasyORef(oref string) error { func validateEasyORef(oref string) error {
if oref == "this" { if oref == "this" || oref == "tab" {
return nil return nil
} }
if num, err := strconv.Atoi(oref); err == nil && num >= 1 { if num, err := strconv.Atoi(oref); err == nil && num >= 1 {

View File

@ -33,6 +33,7 @@ import (
) )
const SimpleId_This = "this" const SimpleId_This = "this"
const SimpleId_Tab = "tab"
var SimpleId_BlockNum_Regex = regexp.MustCompile(`^\d+$`) var SimpleId_BlockNum_Regex = regexp.MustCompile(`^\d+$`)
@ -160,6 +161,16 @@ func resolveSimpleId(ctx context.Context, data wshrpc.CommandResolveIdsData, sim
} }
return &waveobj.ORef{OType: waveobj.OType_Block, OID: data.BlockId}, nil return &waveobj.ORef{OType: waveobj.OType_Block, OID: data.BlockId}, nil
} }
if simpleId == SimpleId_Tab {
if data.BlockId == "" {
return nil, fmt.Errorf("no blockid in request")
}
tabId, err := wstore.DBFindTabForBlockId(ctx, data.BlockId)
if err != nil {
return nil, fmt.Errorf("error finding tab: %v", err)
}
return &waveobj.ORef{OType: waveobj.OType_Tab, OID: tabId}, nil
}
blockNum, err := strconv.Atoi(simpleId) blockNum, err := strconv.Atoi(simpleId)
if err == nil { if err == nil {
tabId, err := wstore.DBFindTabForBlockId(ctx, data.BlockId) tabId, err := wstore.DBFindTabForBlockId(ctx, data.BlockId)