MCPcopy Index your code
hub / github.com/retspen/webvirtcloud / XmlBehaviour

Function XmlBehaviour

static/js/mode-xml.js:223–365  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

221}
222
223var XmlBehaviour = function () {
224
225 this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
226 if (text == '"' || text == "'") {
227 var quote = text;
228 var selected = session.doc.getTextRange(editor.getSelectionRange());
229 if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
230 return {
231 text: quote + selected + quote,
232 selection: false
233 };
234 }
235
236 var cursor = editor.getCursorPosition();
237 var line = session.doc.getLine(cursor.row);
238 var rightChar = line.substring(cursor.column, cursor.column + 1);
239 var iterator = new TokenIterator(session, cursor.row, cursor.column);
240 var token = iterator.getCurrentToken();
241
242 if (rightChar == quote && (is(token, "attribute-value") || is(token, "string"))) {
243 return {
244 text: "",
245 selection: [1, 1]
246 };
247 }
248
249 if (!token)
250 token = iterator.stepBackward();
251
252 if (!token)
253 return;
254
255 while (is(token, "tag-whitespace") || is(token, "whitespace")) {
256 token = iterator.stepBackward();
257 }
258 var rightSpace = !rightChar || rightChar.match(/\s/);
259 if (is(token, "attribute-equals") && (rightSpace || rightChar == '>') || (is(token, "decl-attribute-equals") && (rightSpace || rightChar == '?'))) {
260 return {
261 text: quote + quote,
262 selection: [1, 1]
263 };
264 }
265 }
266 });
267
268 this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
269 var selected = session.doc.getTextRange(range);
270 if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
271 var line = session.doc.getLine(range.start.row);
272 var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
273 if (rightChar == selected) {
274 range.end.column++;
275 return range;
276 }
277 }
278 });
279
280 this.add("autoclosing", "insertion", function (state, action, editor, session, text) {

Callers

nothing calls this directly

Calls 1

isFunction · 0.85

Tested by

no test coverage detected