-
Notifications
You must be signed in to change notification settings - Fork 153
JS to TS : simulator/src/data/undo.ts #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d30b2a5
add
ThatDeparted2061 00cb77e
remove
ThatDeparted2061 cd3d5b1
fix null
ThatDeparted2061 c360c82
resolve 2
ThatDeparted2061 28fe316
reslove cognitive complexity
ThatDeparted2061 de25c47
Merge branch 'main' into undo.js
ThatDeparted2061 7c11cc8
Merge branch 'main' into undo.js
Arnabdaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 26 additions & 18 deletions
44
src/simulator/src/data/undo.js → src/simulator/src/data/undo.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,59 @@ | ||
/* eslint-disable import/no-cycle */ | ||
/** | ||
* Function to restore copy from backup | ||
* @param {Scope=} scope - The circuit on which undo is called | ||
* @category data | ||
*/ | ||
import { layoutModeGet } from '../layoutMode' | ||
import Scope, { scopeList } from '../circuit' | ||
import { loadScope } from './load' | ||
import { updateRestrictedElementsInScope } from '../restrictedElementDiv' | ||
import { forceResetNodesSet } from '../engine' | ||
|
||
// Declare global variables | ||
declare let globalScope: Scope | ||
declare let loading: boolean | ||
|
||
/** | ||
* Function called to generate a prompt to save an image | ||
* @param {Scope=} - the circuit in which we want to call undo | ||
* Function to restore copy from backup | ||
* @param scope - The circuit on which undo is called | ||
* @category data | ||
* @exports undo | ||
*/ | ||
export default function undo(scope = globalScope) { | ||
export default function undo(scope: Scope = globalScope): void { | ||
if (layoutModeGet()) return | ||
if (scope.backups.length < 2) return | ||
const backupOx = globalScope.ox | ||
const backupOy = globalScope.oy | ||
const backupScale = globalScope.scale | ||
|
||
const backupOx: number = globalScope.ox | ||
const backupOy: number = globalScope.oy | ||
const backupScale: number = globalScope.scale | ||
|
||
globalScope.ox = 0 | ||
globalScope.oy = 0 | ||
const tempScope = new Scope(scope.name) | ||
|
||
const tempScope: Scope = new Scope(scope.name) | ||
loading = true | ||
const undoData = scope.backups.pop() | ||
|
||
const undoData: string = scope.backups.pop()! | ||
scope.history.push(undoData) | ||
scope.backups.length !== 0 && | ||
|
||
if (scope.backups.length !== 0) { | ||
loadScope( | ||
tempScope, | ||
JSON.parse(scope.backups[scope.backups.length - 1]) | ||
) | ||
} | ||
ThatDeparted2061 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
tempScope.backups = scope.backups | ||
tempScope.history = scope.history | ||
tempScope.id = scope.id | ||
tempScope.name = scope.name | ||
tempScope.testbenchData = scope.testbenchData | ||
|
||
scopeList[scope.id] = tempScope | ||
globalScope = tempScope | ||
|
||
globalScope.ox = backupOx | ||
globalScope.oy = backupOy | ||
globalScope.scale = backupScale | ||
|
||
loading = false | ||
forceResetNodesSet(true) | ||
|
||
// Updated restricted elements | ||
// Update restricted elements | ||
updateRestrictedElementsInScope() | ||
} | ||
// for html file | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.