<commit_before>import { Constants } from "../constants";
import { Composer } from "../views/composer";

Composer.RegisterKeyboardHandler(function(e) {
  return (
    e.type === "keydown" &&
    e.keyCode == Constants.BACKSPACE_KEY
  );
}, function(editor, composer, e) {
  var range = composer.selection.getRange();
  if (range && range.collapsed && range.startOffset == 0) {
    var selectedNode = composer.selection.getSelectedNode();
    if (
      selectedNode &&
      selectedNode === composer.element.firstElementChild &&
      selectedNode === composer.element.lastElementChild
    ) {
      e.preventDefault();
    }
  }
})<commit_msg>Use more bulletproof start of range detection<commit_after>import { Constants } from "../constants";
import { Composer } from "../views/composer";

Composer.RegisterKeyboardHandler(function(e) {
  return (
    e.type === "keydown" &&
    e.keyCode == Constants.BACKSPACE_KEY
  );
}, function(editor, composer, e) {
  var range = composer.selection.getRange();
  if (range && range.collapsed) {
    var selectedNode = composer.selection.getSelectedNode();
    if (
      selectedNode &&
      selectedNode === composer.element.firstElementChild &&
      selectedNode === composer.element.lastElementChild &&
      composer.selection.caretIsAtStartOfNode(selectedNode)
    ) {
      e.preventDefault();
    }
  }
})
{'fraction_non_alphanumeric': 0.14075165806927045, 'fraction_numerical': 0.0007369196757553427, 'mean_word_length': 3.557046979865772, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6885486', 'n_tokens_mistral': 388, 'n_tokens_neox': 395, 'n_words': 75}