Przeglądaj źródła

[spark] Codemirror default placeholder disappears on focus and reappears on blur if empty

Enrico Berti 10 lat temu
rodzic
commit
0b1495c
1 zmienionych plików z 12 dodań i 0 usunięć
  1. 12 0
      apps/spark/src/spark/templates/editor.mako

+ 12 - 0
apps/spark/src/spark/templates/editor.mako

@@ -978,6 +978,18 @@ ${ commonheader(_('Query'), app_name, user, "68px") | n,unicode }
         }, 600);
       });
 
+      editor.on("focus", function () {
+        if (editor.getValue() == viewModel.snippetPlaceholders[snippet.type()]) {
+          editor.setValue("");
+        }
+      });
+
+      editor.on("blur", function () {
+        if (editor.getValue() == ""){
+          editor.setValue(viewModel.snippetPlaceholders[snippet.type()]); 
+        }
+      });
+
       ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
         wrapperElement.remove();
       });