<commit_before>// Various helper function for working with tables

import {PluginKey} from "prosemirror-state"

import {TableMap} from "./tablemap"

export const key = new PluginKey("selectingCells")

export function cellAround($pos) {
  for (let d = $pos.depth - 1; d > 0; d--)
    if ($pos.node(d).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d + 1))
  return null
}

export function cellWrapping($pos) {
  for (let d = $pos.depth - 1; d > 0; d--) {
    const role = $pos.node(d).type.spec.tableRole;
    if (role === "cell" || role === 'header_cell') return $pos.node(d)
  }
  return null
}

export function isInTable(state) {
  let $head = state.selection.$head
  for (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec.tableRole == "row") return true
  return false
}
<commit_msg>Fix cell wrapping no checking in the current depth<commit_after>// Various helper function for working with tables

import {PluginKey} from "prosemirror-state"

import {TableMap} from "./tablemap"

export const key = new PluginKey("selectingCells")

export function cellAround($pos) {
  for (let d = $pos.depth - 1; d > 0; d--)
    if ($pos.node(d).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d + 1))
  return null
}

export function cellWrapping($pos) {
  for (let d = $pos.depth; d > 0; d--) { // Sometimes the cell can be in the same depth.
    const role = $pos.node(d).type.spec.tableRole;
    if (role === "cell" || role === 'header_cell') return $pos.node(d)
  }
  return null
}

export function isInTable(state) {
  let $head = state.selection.$head
  for (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec.tableRole == "row") return true
  return false
}

{'fraction_non_alphanumeric': 0.16269610691458455, 'fraction_numerical': 0.007553747821034283, 'mean_word_length': 3.641509433962264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5027747', 'n_tokens_mistral': 606, 'n_tokens_neox': 593, 'n_words': 182}