!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("../fold/xml-fold")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../fold/xml-fold"],t):t(CodeMirror)}(function(n){"use strict";function c(t){t.state.tagHit&&t.state.tagHit.clear(),t.state.tagOther&&t.state.tagOther.clear(),t.state.tagHit=t.state.tagOther=null}function o(r){r.state.failedTagMatch=!1,r.operation(function(){if(c(r),!r.somethingSelected()){var t=r.getCursor(),e=r.getViewport();e.from=Math.min(e.from,t.line),e.to=Math.max(t.line+1,e.to);var a=n.findMatchingTag(r,t,e);if(a){if(r.state.matchBothTags){var o="open"==a.at?a.open:a.close;o&&(r.state.tagHit=r.markText(o.from,o.to,{className:"CodeMirror-matchingtag"}))}var i="close"==a.at?a.open:a.close;i?r.state.tagOther=r.markText(i.from,i.to,{className:"CodeMirror-matchingtag"}):r.state.failedTagMatch=!0}}})}function i(t){t.state.failedTagMatch&&o(t)}n.defineOption("matchTags",!1,function(t,e,a){a&&a!=n.Init&&(t.off("cursorActivity",o),t.off("viewportChange",i),c(t)),e&&(t.state.matchBothTags="object"==typeof e&&e.bothTags,t.on("cursorActivity",o),t.on("viewportChange",i),o(t))}),n.commands.toMatchingTag=function(t){var e=n.findMatchingTag(t,t.getCursor());if(e){var a="close"==e.at?e.open:e.close;a&&t.extendSelection(a.to,a.from)}}});