const getNewRowCursorPosition = function (editor, table) { const rows = SelectorFilter.descendants(table, 'tr'); return Arr.last(rows).bind(function (last) { return SelectorFind.descendant(last, 'td,th').map(function (first) { return getCellFirstCursorPosition(editor, first); }); }); };
const createJoinedSections = (scope: Document, length: number, listType: ListType): Section[] => { const sections: Section[] = []; for (let i = 0; i < length; i++) { const newSection = createSection(scope, listType); Arr.last(sections).each((lastSection) => joinSections(lastSection, newSection)); sections.push(newSection); } return sections; };
const populateSegments = (segments: Segment[], entry: Entry): void => { for (let i = 0; i < segments.length - 1; i++) { Css.set(segments[i].item, 'list-style-type', 'none'); } Arr.last(segments).each((segment) => { Attr.setAll(segment.list, entry.listAttributes); Attr.setAll(segment.item, entry.itemAttributes); InsertAll.append(segment.item, entry.content); }); };
const writeDeep = (scope: Document, outline: Section[], entry: Entry): Section[] => { const newSections = createJoinedSections(scope, entry.depth - outline.length, entry.listType); populateSections(newSections, entry); Options.liftN([ Arr.last(outline), Arr.head(newSections) ], joinSections); return outline.concat(newSections); };
const writeShallow = (scope: Document, outline: Section[], entry: Entry): Section[] => { const newOutline = outline.slice(0, entry.depth); Arr.last(newOutline).each((section) => { setItem(section, createItem(scope, entry.itemAttributes, entry.content)); normalizeSection(section, entry); }); return newOutline; };
const writeShallow = (scope: Document, cast: Segment[], entry: Entry): Segment[] => { const newCast = cast.slice(0, entry.depth); Arr.last(newCast).each((segment) => { const item = createItem(scope, entry.itemAttributes, entry.content); appendItem(segment, item); normalizeSegment(segment, entry); }); return newCast; };
AlloyEvents.run<BackwardSlideEvent>(backSlideEvent, (comp, se) => { Arr.last(stack.get()).each((last) => { stack.set(stack.get().slice(0, stack.get().length - 1)); AlloyTriggers.emitWith(comp, changeSlideEvent, { // Because we are using premade, we should have access to the same element // to give focus (although it isn't working) contents: GuiFactory.premade(last.bar), focus: last.focus }); }); }),
return () => { const from = forward ? CaretPosition.fromRangeEnd(editor.selection.getRng()) : CaretPosition.fromRangeStart(editor.selection.getRng()); const result = forward ? getPositionsUntilNextLine(editor.getBody(), from) : getPositionsUntilPreviousLine(editor.getBody(), from); const to = forward ? Arr.last(result.positions) : Arr.head(result.positions); return to.filter(isCefPosition(forward)).fold( Fun.constant(false), (pos) => { editor.selection.setRng(pos.toRange()); return true; } ); };
onEscape: (comp) => { return Arr.last(stack.get()).fold( () => { // Escape just focuses the content. It no longer closes the toolbar. return spec.onEscape(); }, (_) => { AlloyTriggers.emit(comp, backSlideEvent); return Option.some(true); } ); }
const addContextMenuGroup = (xs: Array<MenuItem>, groupItems: Array<MenuItem>) => { // Skip if there are no items if (groupItems.length === 0) { return xs; } // Only add a separator at the beginning if the last item isn't a separator const lastMenuItem = Arr.last(xs).filter((item) => !isSeparator(item)); const before = lastMenuItem.fold( () => [], (_) => [ separator ] ); return xs.concat(before).concat(groupItems).concat([ separator ]); };