Diff Editor

October 13, 2019 ยท View on GitHub

The diff editor is contained in a Split editor and will highlight differences between the two editor boxes.

Demo

Example Code

import React, { Component } from "react";
import { render } from "react-dom";
import { diff as DiffEditor } from "react-ace";

import "ace-builds/src-noconflict/theme-github";

render(
  <DiffEditor
    value={["Test code differences", "Test code difference"]}
    height="1000px"
    width="1000px"
    mode="text"
  />
);

Also see the diff example in the example folder for more robust sample code (seen in the demo).

Available Props

PropDefaultTypeDescription
cursorStart1Numberthe location of the cursor
editorPropsObjectproperties to apply directly to the Ace editor instance
enableBasicAutocompletionfalseBooleanEnable basic autocompletion
enableLiveAutocompletionfalseBooleanEnable live autocompletion
focusfalseBooleanWhether to focus
fontSize12Numberpixel value for font-size
height'500px'StringCSS value for height
highlightActiveLinetrueBooleanhighlight active line
maxLinesNumberMaximum number of lines to be displayed
minLinesNumberMinimum number of lines to be displayed
mode''StringThe language to be used for the editor (Java, Javascript, Ruby, etc.)
name'ace-editor'stringUnique ID to be used for the split editor
onLoadFunctioncalled on editor load. The first argument is the instance of the editor
onScrollFunctiontriggered by editor scroll event
onChangeFunctionoccurs on document change it has one argument the values array
onPasteFunctionTriggered by editor paste event, and passes text as argument
orientation'beside'StringThe orientation of splits either 'beside' or 'below'
readOnlyfalseBooleanmake the editor read only
scrollMargin[0, 0, 0, 0]Array of NumbersSets the scroll margins
setOptionsObjectoptions to apply directly to the Ace editor instance
showGuttertrueBooleanshow gutter
showPrintMargintrueBooleanshow print margin
styleObjectcamelCased properties
tabSize4NumberNumber of spaces to include as tab
theme'github'StringTheme to use
value['','']Array of StringsIndex 0: Value of first editor. Index 1: Value of second editor
width'500px'StringCSS value for width
wrapEnabledtrueBooleanWhether lines wrap on the editor