Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: server/static/rpcexplorer/rpc-editor.html

Issue 1695893004: RPC Explorer (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@rpcepxlorer-deps
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!--
2 ~ // Copyright 2016 The Chromium Authors. All rights reserved.
3 ~ // Use of this source code is governed by a BSD-style license that can be
4 ~ // found in the LICENSE file.
5 ~
6 -->
7
8 <link rel="import" href="/static/common/third_party/polymer/polymer.html">
9
10 <script src="third_party/ace/ace.js"></script>
11 <script src="third_party/ace/ext-language_tools.js"></script>
12 <script src="third_party/ace/mode-json.js"></script>
13
14 <link rel="import" href="rpc-completer.html">
15
16 <!-- The `rpc-editor` is an Ace editor for JSON with optional autocomplete -->
17 <dom-module id="rpc-editor">
18 <template>
19 <style>
20 :host, pre {
21 display: block;
22 height: 100%;
23 }
24 </style>
25 <pre id="editor" class="editor"></pre>
26 <rpc-completer id="completer"
27 description="[[description]]" root-type-name="[[rootTypeName]]">
Bons 2016/02/13 17:18:26 four-space indent on continuing lines.
nodir 2016/02/17 02:02:13 Done.
28 </rpc-completer>
29 </template>
30
31 <script>
32 'use strict';
33
34 Polymer({
35 is: 'rpc-editor',
36 properties: {
37 value: {
38 type: String,
39 notify: true,
40 observer: 'onValueChanged'
41 },
42 editor: {
43 type: Object,
44 readOnly: true
45 },
46
47 // Autocomplete.
Bons 2016/02/13 17:18:27 this comment doesn't contain any context. either e
nodir 2016/02/17 02:02:13 removed
48 description: Object, // FileDescriptorSet message
49 rootTypeName: String
50 },
51
52 ready: function() {
53 var self = this;
54 this._setEditor(ace.edit(this.$.editor));
55 this.editor.session.setMode('ace/mode/json');
56
57 // Set and sync text;
58 this.editor.session.setValue(this.value || '');
59 this.editor.session.on('change', function() {
60 var text = self.editor.session.getValue();
61 if (text !== self.value) {
62 self._maybeSync(function() {
63 self.value = text;
64 });
65 }
66 });
67
68 this.editor.commands.removeCommands(['gotoline', 'find']);
69
70 this.editor.setOptions({
71 enableBasicAutocompletion: [this.$.completer],
72 });
73 },
74
75 onValueChanged: function(newVal) {
76 var newText = newVal || '';
77 if (this.editor && this.editor.session.getValue() != newText) {
78 this._maybeSync(function() {
79 var selection = this.editor.selection;
80 var origRange = selection.getRange();
81 this.editor.session.setValue(newText);
82 // Restore cursor position, in a lame way, best effort.
83 selection.setSelectionRange(origRange);
84 })
85 }
86 },
87
88 _maybeSync: function(action) {
89 if (this._syncing) {
90 return;
91 }
92 this._syncing = true;
93 try {
94 action.call(this);
95 } finally {
96 this._syncing = false;
97 }
98 }
99 });
100 </script>
101 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698