# Code Rewriting Tools

## Overview

This section covers several essential tools designed to aid developers in managing and modifying their code efficiently.

## Revert File

Near the top of the [Script Editor context menu](https://docs.servoy.com/reference/servoy-developer/object-editors/getting-started#editor-area-context-menu-commands) is the `Revert File` command. `Revert File` resets an unsaved script to the last saved change.

## Compare and Replace

Servoy keeps a record of all saved changes to a file.

### To access and review previous versions of a script:

1. Use the `Compare With` command towards the bottom of the context menu in Script Editor. A file revision history will be shown on the right History view, with the last saved dates and times.
2. Double-click on your desired save date/time. The Script Editor will show a split pane window containing the current and previous versions, along with change indicators and navigational buttons to assist you in reviewing changes.

   <figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-7ee385f9f9242e6befa0d3d4dcc3503884c1b068%2Fscript-editor-compare.jpg?alt=media" alt=""><figcaption></figcaption></figure>
3. Use the buttons on the top right of the comparison editor window to scroll through and make changes to the original file:

   <figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-6f4050170099fa816d548c723ab948c8884b2dae%2Fscript-editor-compare-buttons.jpg?alt=media" alt=""><figcaption></figcaption></figure>

   * a = Swap Left and Right view
   * b = Copy all non-conflicting differences from right to left
   * c = Copy current (selected difference) from right to left
   * d = Next difference (scrolls through line differences)
   * e = Previous difference
   * f = Next change (jumps to actual character or piece of code that changed within a difference)
   * g = Previous change
4. `Save` the file and close the compare window.

{% hint style="info" %}
Note\
All changes made in the left pane will be reflected in all open instances of the file (ie, the existing editor screen), even without saving.
{% endhint %}

{% hint style="info" %}
Note\
You can find more information about the Compare Editor [here](https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-25.htm).
{% endhint %}

### To go straight to replacing the existing code with the last saved version:

Select `Replace With > Previous From Local History` from the context menu. The editor window will revert to the last saved version.

### To review and replace the existing code with a previously saved version:

1. Select `Replace With > Local History`. A Compare Window will appear.
2. Double-click on the desired date/time for the file you would like to replace the current version.
   * A split pane will appear highlighting the changes.

     <figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-46eed654fc0c38195fca0e1c87bd73a3ad00d055%2Fscript-editor-compare-local.jpg?alt=media" alt=""><figcaption></figcaption></figure>
3. Review the changes using the navigational buttons provided.
4. Click on `Replace` to complete the replace process.

{% hint style="info" %}
Note\
In the Replace With mode, there is no option to replace each change individually.
{% endhint %}

## Toggle Block Selection

The Toggle Block Selection feature is available from the main toolbar, next to the `Mark Occurrences` button.

<figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-05f4e318c0b5afd50345605d954308e7742c6dce%2Fscript-editor-toggle-block.jpg?alt=media" alt=""><figcaption></figcaption></figure>

This feature allows users to select a block of text (column select) and make identical changes to each line. In the example below, the first four parts of the code are selected using Toggle Block Selection mode:

<figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-6557159cf473bc3f94c830254fab62b2079f3814%2Fscript-editor-toggle-block2.jpg?alt=media" alt=""><figcaption></figcaption></figure>

The selected block of text can then be replaced with new code parts, with the user typing only once.
