Skip to content

Commit

Permalink
fix(cli): calculate padding of super.onCreate(savedInstanceState); li…
Browse files Browse the repository at this point in the history
…ne (#6016)
  • Loading branch information
jcesarmobile authored Oct 21, 2022
1 parent f9ec5a3 commit 5729ac1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,19 +955,18 @@ async function migrateMainActivity(config: Config) {
}

const rindex = data.indexOf('registerPlugin');
const superLine = 'super.onCreate(savedInstanceState);';
if (rindex !== -1) {
if (data.indexOf('super.onCreate(savedInstanceState);') < rindex) {
data = data.replace(
'super.onCreate(savedInstanceState);\n ',
'',
);
if (data.indexOf(superLine) < rindex) {
const linePadding =
rindex - data.indexOf(superLine) - superLine.length - 1;
data = data.replace(`${superLine}\n${' '.repeat(linePadding)}`, '');
const eindex = data.lastIndexOf('.class);') + 8;
data = data.replace(
data.substring(bindex, eindex),
`${data.substring(
bindex,
eindex,
)}\n super.onCreate(savedInstanceState);`,
`${data.substring(bindex, eindex)}\n${
' '.repeat(linePadding) + superLine.padStart(linePadding)
}`,
);
}
}
Expand Down

0 comments on commit 5729ac1

Please sign in to comment.