"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.outdentList = outdentList;

var _selection = require("../utils/selection");

var _find = require("../utils/find");

var _outdentListItemsSelected = require("../actions/outdent-list-items-selected");

function outdentList() {
  return function (state, dispatch) {
    if (!(0, _selection.isInsideListItem)(state)) {
      return false;
    }

    var $from = state.selection.$from;
    var parentListNode = (0, _find.findFirstParentListNode)($from);

    if (!parentListNode) {
      // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
      return true;
    }

    var customTr = state.tr;
    (0, _outdentListItemsSelected.outdentListItemsSelected)(customTr);

    if (!customTr || !customTr.docChanged) {
      // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
      // If inside table cell and can't outdent list, then let it handle by table keymap
      return !(0, _selection.isInsideTableCell)(state);
    }

    if (dispatch) {
      dispatch(customTr);
    }

    return true;
  };
}