User pressed Enter in an editor

Enter in a list item should split the list item
Enter in an empty list item should remove it
Shift+Enter in a list item should make a new line
13451
function onEnter(
    event: *,
    change: Change,
    editor: *,
    opts: Options
): void | any {
    // Pressing Shift+Enter
    // should split block normally
    if (event.shiftKey) {
        return undefined;
    }

    const { value } = change;
    const currentItem = getCurrentItem(opts, value);

    // Not in a list
    if (!currentItem) {
        return undefined;
    }

    event.preventDefault();

    // If expanded, delete first.
    if (value.isExpanded) {
        change.delete();
    }

    if (currentItem.isEmpty) {
        // Block is empty, we exit the list
        if (getItemDepth(opts, value) > 1) {
            return decreaseItemDepth(opts, change);
        }
        // Exit list
        return unwrapList(opts, change);
    }
    // Split list item
    return splitListItem(opts, change);
}
1277660
function(e) {
			var self = this;
			if (self.isFull() || self.isInputHidden || self.isLocked) {
				e.preventDefault();
			} else {
				// If a regex or string is included, this will split the pasted
				// input and create Items for each separate value
				if (self.settings.splitOn) {
					setTimeout(function() {
						var splitInput = $.trim(self.$control_input.val() || '').split(self.settings.splitOn);
						for (var i = 0, n = splitInput.length; i < n; i++) {
							self.createItem(splitInput[i]);
						}
					}, 0);
				}
			}
		}
1368571
function normalListItem(ctx, value, position) {
  var offsets = ctx.offset
  var line = position.line
  var max
  var bullet
  var rest
  var lines
  var trimmedLines
  var index
  var length

  // Remove the list-item’s bullet.
  value = value.replace(bulletExpression, replacer)

  lines = value.split(lineFeed)

  trimmedLines = removeIndent(value, getIndent(max).indent).split(lineFeed)

  // We replaced the initial bullet with something else above, which was used
  // to trick `removeIndentation` into removing some more characters when
  // possible.  However, that could result in the initial line to be stripped
  // more than it should be.
  trimmedLines[0] = rest

  offsets[line] = (offsets[line] || 0) + bullet.length
  line++

  index = 0
  length = lines.length

  while (++index < length) {
    offsets[line] =
      (offsets[line] || 0) + lines[index].length - trimmedLines[index].length
    line++
  }

  return trimmedLines.join(lineFeed)

  function replacer($0, $1, $2, $3, $4) {
    bullet = $1 + $2 + $3
    rest = $4

    // Make sure that the first nine numbered list items can indent with an
    // extra space.  That is, when the bullet did not receive an extra final
    // space.
    if (Number($2) < 10 && bullet.length % 2 === 1) {
      $2 = space + $2
    }

    max = $1 + repeat(space, $2.length) + $3

    return max + rest
  }
}
143364
def linedelimited (inlist,delimiter):
    
    outstr = ''
    for item in inlist:
        if type(item) != StringType:
            item = str(item)
        outstr = outstr + item + delimiter
    outstr = outstr[0:-1]
    return outstr
668054
function(e) {
    if (this.props.parameters.autoIndent) {
      var state = this.state.state;
      var selection = state.getSelection();

      var indentationLevel = indentationLevelAt(state.getCurrentContent(),
                                                selection.getFocusKey(),
                                                selection.getFocusOffset());

      if (state.getCurrentContent().getBlockForKey(selection.getFocusKey())
               .getText().substr(selection.getFocusOffset())
               .trim().startsWith("}")) {
        indentationLevel--;
      }

      state = EditorState.push(
          state,
          this._insertLineAfter(state.getCurrentContent(),
            selection,
            this._generateIndentation(indentationLevel)),
          "inserted-text"
          );

      this.setState({state: state});

      return "handled";
    } else {
      return "not-handled";
    }
  }
1133711
function parseConsecutiveLists(list, listType, trimTrailing) {
    // check if we caught 2 or more consecutive lists by mistake
    // we use the counterRgx, meaning if listType is UL we look for OL and vice versa
    var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
        ulRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?[*+-][ \t]/gm : /^ {0,3}[*+-][ \t]/gm,
        counterRxg = (listType === 'ul') ? olRgx : ulRgx,
        result = '';

    if (list.search(counterRxg) !== -1) {
      (function parseCL(txt) {
        var pos = txt.search(counterRxg);
        if (pos !== -1) {
          // slice
          result += '\n<' + listType + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';

          // invert counterType and listType
          listType = (listType === 'ul') ? 'ol' : 'ul';
          counterRxg = (listType === 'ul') ? olRgx : ulRgx;

          //recurse
          parseCL(txt.slice(pos));
        } else {
          result += '\n<' + listType + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
        }
      })(list);
    } else {
      result = '\n<' + listType + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
    }

    return result;
  }
908677
def on_enter(self, *args):
        
        if self.text == '':
            return
        self.setter(self.text)
        self.text = ''
        self.focus = False
24516
function(str, indent) {
			var lines = str.split("\n");
			for (var i=0; i<lines.length; i++)
				lines[i] = indent + lines[i];
			return lines.join("\n");
		}
574646
def cut(self):
        
        tc = self.textCursor()
        helper = TextHelper(self)
        tc.beginEditBlock()
        no_selection = False
        sText = tc.selection().toPlainText()
        if not helper.current_line_text() and sText.count("\n") > 1:
            tc.deleteChar()
        else:
            if not self.textCursor().hasSelection():
                no_selection = True
                TextHelper(self).select_whole_line()
            super(CodeEdit, self).cut()
            if no_selection:
                tc.deleteChar()
        tc.endEditBlock()
        self.setTextCursor(tc)
1031136
def _split(self, split_cls, editor_buffer=None):
        
        if editor_buffer is None:
            editor_buffer = self.active_window.editor_buffer

        active_split = self._get_active_split()
        index = active_split.index(self.active_window)
        new_window = Window(editor_buffer)

        if isinstance(active_split, split_cls):
            # Add new window to active split.
            active_split.insert(index, new_window)
        else:
            # Split in the other direction.
            active_split[index] = split_cls([active_split[index], new_window])

        # Focus new window.
        self.active_window = new_window
569432
def edit_line lineno=@current_index
      line = self[lineno]
      prompt = "Edit: "
      maxlen = 80
      config={}; 
      oldline = line.dup
      config[:default] = line
      ret, str = rb_getstr(@form.window, $error_message_row, $error_message_col,  prompt, maxlen, config)
      $log.debug " rb_getstr returned #{ret} , #{str} "
      return if ret != 0
      # we possibly cou;d have done []= but maybe in textpad or something that would replace a row pointer ??
      self[lineno].replace(str)
      fire_handler :CHANGE, InputDataEvent.new(0,oldline.length, self, :DELETE_LINE, lineno, oldline)     #  2008-12-24 18:34 
      fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
      fire_row_changed lineno
    end
1085988
def split_focus(self):
        """"""

        focus = self.lines[self.focus]
        pos = focus.edit_pos
        edit = urwid.Edit("", focus.edit_text[pos:], allow_tab=True)
        edit.original_text = ""
        focus.set_edit_text(focus.edit_text[:pos])
        edit.set_edit_pos(0)
        self.lines.insert(self.focus + 1, edit)
1041934
def onShortcutIndentAfterCursor(self):
        
        cursor = self._qpart.textCursor()

        def insertIndent():
            if self.useTabs:
                cursor.insertText('\t')
            else:  # indent to integer count of indents from line start
                charsToInsert = self.width - (len(self._qpart.textBeforeCursor()) % self.width)
                cursor.insertText(' ' * charsToInsert)

        if cursor.positionInBlock() == 0:  # if no any indent - indent smartly
            block = cursor.block()
            self.autoIndentBlock(block, '')

            # if no smart indentation - just insert one indent
            if self._qpart.textBeforeCursor() == '':
                insertIndent()
        else:
            insertIndent()
1195745
function splitTag(editor, node, cursor) {
	const open = getText(editor, node.open);
	const m = open.match(/(\s*\/)?>$/);
	const start = node.open.end.translate([0, m ? -m[0].length : 0]);
	editor.setTextInBufferRange(new Range(start, node.open.end), `></${node.name}>`);

	if (cursor) {
		cursor.setBufferPosition(start.translate([0, 1]));
	}
}
1053271
function splitter(target, splitExp) {
		var mw = core.base();
		mw.enabled = true;
		mw.splitExp = (splitExp || /\r?\n/g);
		mw.target = target;
		mw.writeln = function (str) {
			if (mw.enabled) {
				str = String(str);
				var start = 0;
				var match;

				mw.splitExp.lastIndex = 0;
				while ((match = mw.splitExp.exec(str))) {
					var line = str.substring(start, match.index);
					start = match.index + match[0].length;
					mw.splitExp.lastIndex = start;
					mw.target.writeln(line);
				}
				// append piece after final linebreak (or final blank line)
				if (start < str.length || start === str.length) {
					mw.target.writeln(str.substr(start));
				}
			}
		};
		mw.toString = function () {
			return '<miniwrite-splitter>';
		};
		return mw;
	}
1210020
def insert off0, data
       _maxlen = @maxlen || @width - @internal_width
      if data.length > _maxlen
        data = wrap_text data
      #  $log.debug "after wrap text done :#{data}"
        data = data.split("\n")
        data[-1] << "\r" #XXXX
      data.each do |row|
        @list.insert off0, row
        off0 += 1
      end
      else
        data << "\r" if data[-1,1] != "\r" #XXXX
        @list.insert off0, data
      end
      # expecting array !! 
      #data.each do |row|
        #@list.insert off0, row
        #off0 += 1
      #end
      #$log.debug " AFTER INSERT: #{@list}"
    end
1180571
function remove(item, list) {
  var i = list.indexOf(item);
  if (~i) list.splice(i, 1);
}