[英]goJS get node into edit mode on key press
我正在使用goJS制作一些圖形。 試圖提供更好的用戶體驗,以便當用戶選擇一個節點並按下鍵盤上的任何字母數字鍵,插入點或空格鍵時,該節點會自動進入編輯模式。
該用戶將寫一些文本並在節點外部按下Enter鍵或單擊鼠標時,文本將保留在節點內部。
到目前為止,我做了這個nodeClicked函數,如果用戶按住Shift +鼠標單擊,它將成功注冊事件。 但是我無法進入編輯模式,需要幫助。 這是我的nodeClicked函數:
function nodeClicked(e, obj) { // executed by click and doubleclick handlers
var evt = e.copy();
var node = obj.part;
if(evt.diagram.lastInput.shift){
evt.diagram.commandHandler.editTextBlock(node.findObject("TEXTBLOCK"));
}
}
這是我的節點模板:
myDiagram.nodeTemplate =
$(go.Node, "Auto",
{click: nodeClicked},
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
// define the node's outer shape, which will surround the TextBlock
$(go.Shape, "RoundedRectangle",
{
parameter1: 20, // the corner has a large radius
fill: "#cce6ff", // the default fill, if there is no data-binding
stroke: null,
portId: "", // this Shape is the Node's port, not the whole Node
fromLinkable: false, fromLinkableDuplicates: true,
toLinkable: false, toLinkableDuplicates: true,
cursor: "pointer"
},
new go.Binding("fill", "fill"),
new go.Binding("strokeDashArray", "dash"),
new go.Binding("strokeWidth", "width")),
$(go.TextBlock,
{
font: "bold 11pt helvetica, bold arial, sans-serif",
textValidation: okName,
isMultiline: false,
editable: true // editing the text automatically updates the model data
//textEditor: window.TextEditorRadioButtons, // defined in textEditorRadioButtons.js
// this specific TextBlock has its own choices:
},
new go.Binding("editable", "text", function(t, e) {
return t === "?";
}),
new go.Binding("editable", "text", isFeEditable).makeTwoWay(fromLocation),
new go.Binding("text").makeTwoWay())
);
我還閱讀了有關InputEvent類的文檔,但是找不到使用它的任何示例,因此我對如何實現它有些困惑。
您的nodeClicked
函數假定存在一個名為“ TEXTBLOCK”的TextBlock ,但是您未在Node模板中的任何TextBlock上設置name
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.