import "./cljs_env.js";
goog.provide('clojure_eval.extensions.selection_history');
var module$node_modules$$codemirror$state$dist$index_cjs=shadow.js.require("module$node_modules$$codemirror$state$dist$index_cjs", {});
clojure_eval.extensions.selection_history.event_annotation = clojure_eval.util.user_event_annotation("selectionhistory");
clojure_eval.extensions.selection_history.second_last = (function clojure_eval$extensions$selection_history$second_last(arr){
if((arr.length > (1))){
return (arr[(arr.length - (1))]);
} else {
return null;
}
});
clojure_eval.extensions.selection_history.ser = (function clojure_eval$extensions$selection_history$ser(selection){
return cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.juxt.cljs$core$IFn$_invoke$arity$2(new cljs.core.Keyword(null,"anchor","anchor",1549638489),new cljs.core.Keyword(null,"head","head",-771383919)),new cljs.core.Keyword(null,"ranges","ranges",1887686682).cljs$core$IFn$_invoke$arity$1(cljs.core.js__GT_clj.cljs$core$IFn$_invoke$arity$variadic(selection.toJSON(),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([new cljs.core.Keyword(null,"keywordize-keys","keywordize-keys",1310784252),true], 0))));
});
clojure_eval.extensions.selection_history.something_selected_QMARK_ = (function clojure_eval$extensions$selection_history$something_selected_QMARK_(selection){
return cljs.core.some((function (p1__55317_SHARP_){
return cljs.core.not(p1__55317_SHARP_.empty);
}),selection.ranges);
});
/**
 * Stores selection history
 */
clojure_eval.extensions.selection_history.selection_history_field = module$node_modules$$codemirror$state$dist$index_cjs.StateField.define(({"create": (function (state){
return (new cljs.core.List(null,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"selection","selection",975998651),state.selection], null),null,(1),null));
}), "update": (function (stack,p__55321){
var map__55323 = p__55321;
var map__55323__$1 = (((((!((map__55323 == null))))?(((((map__55323.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55323.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55323):map__55323);
var tr = map__55323__$1;
var map__55324 = (function (){var obj55332 = map__55323__$1;
var k55333 = "state";
if((function (){var obj55336 = obj55332;
return (((!((obj55336 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55333,obj55336)));
})()){
return (obj55332[k55333]);
} else {
return undefined;
}
})();
var map__55324__$1 = (((((!((map__55324 == null))))?(((((map__55324.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55324.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55324):map__55324);
var selection = (function (){var obj55344 = map__55324__$1;
var k55345 = "selection";
if((function (){var obj55346 = obj55344;
return (((!((obj55346 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55345,obj55346)));
})()){
return (obj55344[k55345]);
} else {
return undefined;
}
})();
var docChanged = (function (){var obj55348 = map__55323__$1;
var k55349 = "docChanged";
if((function (){var obj55350 = obj55348;
return (((!((obj55350 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55349,obj55350)));
})()){
return (obj55348[k55349]);
} else {
return undefined;
}
})();
var previous_position = cljs.core.first(cljs.core.keep_indexed.cljs$core$IFn$_invoke$arity$2((function (i,x){
if(cljs.core.truth_(clojure_eval.selections.eq_QMARK_(new cljs.core.Keyword(null,"selection","selection",975998651).cljs$core$IFn$_invoke$arity$1(x),selection))){
return i;
} else {
return null;
}
}),stack));
if(cljs.core.truth_(docChanged)){
return (new cljs.core.List(null,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"selection","selection",975998651),selection,new cljs.core.Keyword(null,"event","event",301435442),clojure_eval.util.get_user_event_annotation(tr)], null),null,(1),null));
} else {
if(cljs.core.not(clojure_eval.extensions.selection_history.something_selected_QMARK_(selection))){
return (new cljs.core.List(null,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"selection","selection",975998651),selection,new cljs.core.Keyword(null,"event","event",301435442),clojure_eval.util.get_user_event_annotation(tr)], null),null,(1),null));
} else {
if(cljs.core.truth_(previous_position)){
var vec__55354 = cljs.core.drop.cljs$core$IFn$_invoke$arity$2(previous_position,stack);
var seq__55355 = cljs.core.seq(vec__55354);
var first__55356 = cljs.core.first(seq__55355);
var seq__55355__$1 = cljs.core.next(seq__55355);
var f = first__55356;
var more = seq__55355__$1;
return cljs.core.cons(cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(f,new cljs.core.Keyword(null,"prev-event","prev-event",-88694225),new cljs.core.Keyword(null,"event","event",301435442).cljs$core$IFn$_invoke$arity$1(cljs.core.first(stack))),more);
} else {
return cljs.core.cons(new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"selection","selection",975998651),selection,new cljs.core.Keyword(null,"event","event",301435442),clojure_eval.util.get_user_event_annotation(tr)], null),stack);

}
}
}
})}));
clojure_eval.extensions.selection_history.extension = (function clojure_eval$extensions$selection_history$extension(){
return clojure_eval.extensions.selection_history.selection_history_field;
});
clojure_eval.extensions.selection_history.stack = (function clojure_eval$extensions$selection_history$stack(state){
return state.field(clojure_eval.extensions.selection_history.selection_history_field);
});
clojure_eval.extensions.selection_history.grow_1 = (function clojure_eval$extensions$selection_history$grow_1(state,start,end){
var node = clojure_eval.node.nearest_touching(state,end,(-1));
return cljs.core.first(cljs.core.filter.cljs$core$IFn$_invoke$arity$2((function (p__55361){
var map__55362 = p__55361;
var map__55362__$1 = (((((!((map__55362 == null))))?(((((map__55362.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55362.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55362):map__55362);
var a_start = (function (){var obj55365 = map__55362__$1;
var k55366 = "from";
if((function (){var obj55368 = obj55365;
return (((!((obj55368 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55366,obj55368)));
})()){
return (obj55365[k55366]);
} else {
return undefined;
}
})();
var a_end = (function (){var obj55370 = map__55362__$1;
var k55371 = "to";
if((function (){var obj55372 = obj55370;
return (((!((obj55372 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55371,obj55372)));
})()){
return (obj55370[k55371]);
} else {
return undefined;
}
})();
return (((a_start <= start)) && ((((a_end >= end)) && ((!((((a_start === start)) && ((a_end === end)))))))));
}),cljs.core.cons(node,cljs.core.mapcat.cljs$core$IFn$_invoke$arity$variadic(cljs.core.juxt.cljs$core$IFn$_invoke$arity$2(clojure_eval.node.inner_span,cljs.core.identity),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([clojure_eval.node.ancestors(node)], 0)))));
});
clojure_eval.extensions.selection_history.selection_grow_STAR_ = (function clojure_eval$extensions$selection_history$selection_grow_STAR_(state){
return clojure_eval.util.update_ranges.cljs$core$IFn$_invoke$arity$3(state,({"annotations": clojure_eval.extensions.selection_history.event_annotation}),(function (p__55385){
var map__55387 = p__55385;
var map__55387__$1 = (((((!((map__55387 == null))))?(((((map__55387.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55387.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55387):map__55387);
var range = map__55387__$1;
var from = (function (){var obj55395 = map__55387__$1;
var k55396 = "from";
if((function (){var obj55397 = obj55395;
return (((!((obj55397 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55396,obj55397)));
})()){
return (obj55395[k55396]);
} else {
return undefined;
}
})();
var to = (function (){var obj55401 = map__55387__$1;
var k55402 = "to";
if((function (){var obj55403 = obj55401;
return (((!((obj55403 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55402,obj55403)));
})()){
return (obj55401[k55402]);
} else {
return undefined;
}
})();
var empty = (function (){var obj55407 = map__55387__$1;
var k55408 = "empty";
if((function (){var obj55409 = obj55407;
return (((!((obj55409 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55408,obj55409)));
})()){
return (obj55407[k55408]);
} else {
return undefined;
}
})();
if(cljs.core.truth_(empty)){
return new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"range","range",1639692286),(function (){var or__4223__auto__ = (function (){var G__55411 = clojure_eval.node.nearest_touching(state,from,(-1));
if((G__55411 == null)){
return null;
} else {
return clojure_eval.node.balanced_range.cljs$core$IFn$_invoke$arity$2(state,G__55411);
}
})();
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
return range;
}
})()], null);
} else {
return new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"range","range",1639692286),(function (){var or__4223__auto__ = (function (){var G__55415 = clojure_eval.extensions.selection_history.grow_1(state,from,to);
if((G__55415 == null)){
return null;
} else {
return clojure_eval.node.range(G__55415);
}
})();
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
return range;
}
})()], null);
}
}));
});
clojure_eval.extensions.selection_history.selection_return_STAR_ = (function clojure_eval$extensions$selection_history$selection_return_STAR_(state){
var temp__5751__auto__ = new cljs.core.Keyword(null,"selection","selection",975998651).cljs$core$IFn$_invoke$arity$1(cljs.core.second(clojure_eval.extensions.selection_history.stack(state)));
if(cljs.core.truth_(temp__5751__auto__)){
var selection = temp__5751__auto__;
return state.update(({"selection": selection, "annotations": clojure_eval.extensions.selection_history.event_annotation}));
} else {
return clojure_eval.util.update_ranges.cljs$core$IFn$_invoke$arity$3(state,({"annotations": clojure_eval.extensions.selection_history.event_annotation}),(function (range){
return new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"cursor","cursor",1011937484),range.from], null);
}));
}
});

//# sourceMappingURL=clojure_eval.extensions.selection_history.js.map
